我们是五月的花海 , 用青春拥抱时|

兴想事成

园龄:12年10个月粉丝:25关注:97

Oracle常用统计

 

测试, 这是测消息

 

1.按天


select to_char(t.STARTDATE+15/24, 'YYYY-MM-DD') as 天,sum(1) as 数量
from HOLIDAY t
group by to_char(t.STARTDATE+15/24, 'YYYY-MM-DD') --
ORDER by 天 NULLS  LAST;

 

 

select trunc(t.STARTDATE, 'DD') as 天,sum(1) as 数量
from HOLIDAY t
group by trunc(t.STARTDATE, 'DD') --
ORDER by 天 NULLS  LAST;


2.按周


select to_char(next_day(t.STARTDATE+15/24 - 7,2),'YYYY-MM-DD') AS 周,sum(1) as 数量 
from HOLIDAY t 
group by to_char(next_day(t.STARTDATE+15/24 - 7,2),'YYYY-MM-DD')ORDER BY 周;

 

 

-- 按自然周统计 
select to_char(t.STARTDATE,'iw') AS 周,sum(1) as 数量
from HOLIDAY t

group by to_char(t.STARTDATE,'iw')
ORDER BY 周;


3.按自然月


select to_char(t.STARTDATE,'YYYY-MM') as 月份,sum(1) as 数量
from HOLIDAY t

GROUP BY
    to_char(t.STARTDATE,'YYYY-MM')
ORDER BY 月份;


4.按季度


select to_char(t.STARTDATE,'q') 季度,sum(1) as 数量
from HOLIDAY t
group by to_char(t.STARTDATE,'q')
ORDER BY 季度 NULLS  LAST;

 

 

5.按年


select to_char(t.STARTDATE,'yyyy') AS 年度,sum(1) as 数量
from HOLIDAY t
group by to_char(t.STARTDATE,'yyyy')
ORDER BY 年度;

 

 

 

 


6.ORACLE用GROUP BY 来分组日期字段 按月分组

 

 

SELECT to_char(日期字段,'yyyymm'),sum(*) 
FROM [TableName] 
group by to_char(日期字段,'yyyymm');
SELECT to_char(日期字段,'yyyymm'),sum(*) 
FROM [TableName] 
group by to_char(日期字段,'yyyymm');

 

 

7.oracle查询七天数据,并且按日期分组

 


1、查从今天开始前七天日期

select to_char (sysdate- level + 1, 'yyyy-mm-dd') today FROM DUAL connect BY LEVEL <= 7

2、写统计语句,将数量和日期查出来(这个分组统计自己写)

3、用第一步和第二步两张表做左关联查询 ,没有的数量用0代替(刚好这几天都有数据,没有的会以0展示出来)

 

 

1) NVL函数

NVL(E1, E2)的功能为:如果E1为NULL,则函数返回E2,否则返回E1本身。但此函数有一定局限,所以就有了NVL2函数。

拓展:NVL2函数:Oracle/PLSQL中的一个函数,Oracle在NVL函数的功能上扩展,提供了NVL2函数。NVL2(E1, E2, E3)的功能为:如果E1为NULL,则函数返回E3,若E1不为null,则返回E2。

 

 

2)substr函数格式 (俗称:字符截取函数)

  格式1: substr(string string, int a, int b);

  格式2: substr(string string, int a) ;

解释:

格式1:
1、string 需要截取的字符串
2、a 截取字符串的开始位置(注:当a等于0或1时,都是从第一位开始截取)
3、b 要截取的字符串的长度

格式2:
1、string 需要截取的字符串
2、a 可以理解为从第a个字符开始截取后面所有的字符串

 

posted @   兴想事成  阅读(57)  评论(0编辑  收藏  举报
历史上的今天:
2015-06-17 动态生成实体类
2015-06-17 EF框架学习手记
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Good-bye My Loneliness ZARD
  2. 2 Say OK Vanessa Hudgens
  3. 3 All The Love In The World The Corrs
  4. 4 Adesso E Fortuna ~炎と永遠~ 加藤いづみ
Say OK - Vanessa Hudgens
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : BIRGISSON, ARNTHOR/KOTECHA, SAVAN

作曲 : Savan Kotecha/Arnthor Birgisson

Vanessa Hudgens - Say OK

Album: V

You are fine

You are fine

You are fine

You are fine

You are sweet

But I'm still a bit naive with my heart

When you're close I don't breathe

I can't find the words to speak

I feel sparks

But I don't wanna be into you

If you are not looking for true love, oh oh

No I don't wanna start seeing you

If I can't be your only one

So tell me when it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

When you call I don't know

If I should pick up the phone every time

I'm not like all my friends

Who keep calling up the boys, I'm so shy

But I don't wanna be into you

If you don't treat me the right way

See I can only start seeing you

If you can make my heart feel safe (feel safe)

When it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away, don't run away)

Let me know if it's gonna be you

Boy, you've got some things to prove

Let me know that you'll keep me safe

I don't want you to run away so

Let me know that you'll call on time

Let me know that you won't be shy

Will you wipe my tears away

Will you hold me closer

When it's not alright

When it's not ok

Will you try to make me feel better

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

(Don't run away, don't run away)

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

Will you say OK

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

You are fine

You are fine