网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

oracle日期怎么分组 oracle按月分组查询

oracle如何按日期分组,底下的代码如何让它成功?

GROUP BY TO_CHAR(ORDER_DATE,'YYYYMMDD')是按order_date的年月日是否相同做日期分组,你那代码执行有什么错误吗

创新互联建站是一家集网站建设,克井企业网站建设,克井品牌网站建设,网站定制,克井网站建设报价,网络营销,网络优化,克井网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

oracle 时间字段是年月日时分秒怎么根据年月日分组

年:

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy');

月:

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm');

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymm');

日:

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd');

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymmdd');

时:

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24');

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymmddhh24');

分:

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi');

group by to_char(to_date(sysdate, 'yyyy-mm-dd hh24:mi:ss'),'yyyymmddhh24mi');

秒:

group by sysdate;

oracle 时间段分组

case when吧

select sum(case when 时间 between '01:01' and '03:00' then 统计字段 else 0 end) "1-3点",

sum(case when 时间 between '03:01' and '05:00' then 统计字段 else 0 end) "3-5点"

from 表名

举例了两个时间段,其他的自己写吧,有问题追问。

Oracle里面如何让一段日期按周、月、季度、年分组显示啊?求高手赐教,贴出正确sql追加高分!

select distinct to_char(dt, 'yyyy-mm-dd') as years,to_char(dt, 'iw') as week

from (select (to_date('2013-4-15', 'yyyy-mm-dd') + rownum - 1) dtfrom dual connect by rownum = to_date('2013-7-15', 'yyyy-mm-dd') -to_date('2013-4-15', 'yyyy-mm-dd'))

group by to_char(dt, 'iw')

ORDER BY years,week

Oracle数据库按时间进行分组统计数据的方法

Oracle按不同时间分组统计的sql

如下表table1:

日期(exportDate)

数量(amount)

--------------

-----------

14-2月

-08

20

10-3月

-08

2

14-4月

-08

6

14-6月

-08

75

24-10月-09

23

14-11月-09

45

04-8月

-10

5

04-9月

-10

44

04-10月-10

88

注意:为了显示更直观,如下查询已皆按相应分组排序

1.按年份分组

select

to_char(exportDate,'yyyy'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy');

年份

数量

-----------------------------

2009

68

2010

137

2008

103

2.按月份分组

select

to_char(exportDate,'yyyy-mm'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy-mm')

order

by

to_char(exportDate,'yyyy-mm');

月份

数量

-----------------------------

2008-02

20

2008-03

2

2008-04

6

2008-06

75

2009-10

23

2009-11

45

2010-08

5

2010-09

44

2010-10

88

3.按季度分组

select

to_char(exportDate,'yyyy-Q'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy-Q')

order

by

to_char(exportDate,'yyyy-Q');

季度

数量

------------------------------

2008-1

22

2008-2

81

2009-4

68

2010-3

49

2010-4

88

4.按周分组

select

to_char(exportDate,'yyyy-IW'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy-IW')

order

by

to_char(exportDate,'yyyy-IW');

数量

------------------------------

2008-07

20

2008-11

2

2008-16

6

2008-24

75

2009-43

23

2009-46

45

2010-31

5

2010-35

44

2010-40

88

PS:Oracle按时间段分组统计

想要按时间段分组查询,首先要了解level,connect

by,oracle时间的加减.

关于level这里不多说,我只写出一个查询语句:

----level

是一个伪例

select

level

from

dual

connect

by

level

=10

---结果:

1

2

3

4

5

6

7

8

9

10

oracle时间的加减看看试一下以下sql语句就会知道:

select

sysdate

-1

from

dual

----结果减一天,也就24小时

select

sysdate-(1/2)

from

dual

-----结果减去半天,也就12小时

select

sysdate-(1/24)

from

dual

-----结果减去1

小时

select

sysdate-((1/24)/12)

from

dual

----结果减去5分钟

select

sydate-(level-1)

from

dual

connect

by

level=10

---结果是10间隔1天的时间

下面是本次例子:

select

dt,

count(satisfy_degree)

as

num

from

T_DEMO

i

,

(select

sysdate

-

(level-1)

*

2

dt

from

dual

connect

by

level

=

10)

d

where

i.satisfy_degree='satisfy_1'

and

i.insert_timedt

and

i.insert_time

d.dt-2

group

by

d.dt

例子中的sysdate

-

(level-1)

*

2得到的是一个间隔是2天的时间

group

by

d.dt

也就是两天的时间间隔分组查询

自己实现例子:

create

table

A_HY_LOCATE1

(

MOBILE_NO

VARCHAR2(32),

LOCATE_TYPE

NUMBER(4),

AREA_NO

VARCHAR2(32),

CREATED_TIME

DATE,

AREA_NAME

VARCHAR2(512),

);

select

(sysdate-13)-(level-1)/4

from

dual

connect

by

level=34

--从第一条时间记录开始(sysdate-13)为表中的最早的日期,“34”出现的分组数(一天按每六个小时分组

就应该为4)

一下是按照每6个小时分组

select

mobile_no,area_name,max(created_time

),dt,

count(*)

as

num

from

a_hy_locate1

i

,

(select

(sysdate-13)-(level-1)/4

dt

from

dual

connect

by

level

=

34)

d

where

i.locate_type

=

1

and

i.created_timedt

and

i.created_time

d.dt-1/4

group

by

mobile_no,area_name,d.dt

另外一个方法:

--按六小时分组

select

trunc(to_number(to_char(created_time,

'hh24'))

/

6),count(*)

from

t_test

where

created_time

trunc(sysdate

-

40)

group

by

trunc(to_number(to_char(created_time,

'hh24'))

/

6)

--按12小时分组

select

trunc(to_number(to_char(created_time,

'hh24'))

/

6),count(*)

from

t_test

where

created_time

trunc(sysdate

-

40)

group

by

trunc(to_number(to_char(created_time,

'hh24'))

/

6)

oracle语句 根据操作时间分组

有个问题,要不要精确到时间,比如再有一条记录为13:05他与12:08的时间没有到达一小时,可是如果直接按照小时排序的话,这就是一个新的序列。如果需要精确到分钟并且以每个用户的第一个时间为准,那就有难度了,因为要判断每个的开始和结束时间进行分组。,而且每一行都要去判断。假设,每59分操作一次,那么这一天都是一个分组。

如果不用那么麻烦,直接就是按照小时分组,那么

select 用户,时间,rank()over(partition by 用户,substr(时间) order by 时间) from table

我不知道你的时间字段是怎么格式,所以直接写的substr可能还需要转化和具体的截取。这里只是写了一个大概的样子


分享标题:oracle日期怎么分组 oracle按月分组查询
本文来源:http://bjjierui.cn/article/hgscdo.html

其他资讯