統計 Oracle按月統計(詳細)

2021-09-30 14:58:32 字數 647 閱讀 2730

--建立表 test

cteate table test(

id number not null,

modifiedtime date not null )

--按月統計

select to_char(t.modifiedtime,'yyyy-mm') time,count(*) count

from test t

--這裡可加查詢條件 where to_char(t.modifiedtime,'yyyy') = to_char(sysdate,'yyyy')

group by to_char(t.modifiedtime,'yyyy-mm') --根據月份來分組

order by to_char(t.modifiedtime,'yyyy-mm') asc nulls last--根據月份來排序

--注:modifiedtime 為 表test裡的時間字段,時間型別

--以上**可直接在資料庫裡執行

--假如表裡還有個數量的字段,要按天統計數量,可將count(*)改為sum(1)函式

【統計】oracle按天統計(詳細)

【統計】oracle按周統計(詳細)

【統計】oracle按季度統計(詳細)

【統計】oracle按年統計(詳細)

按月份統計

id logtimes 12010 03 1213 04 412 2010 04 1313 04 443 2010 05 1813 04 444 2010 06 1813 04 445 2010 07 1813 04 446 2010 05 1813 04 447 2010 05 1813 04 4...

SQL按月統計

做統計就要和時間打交道。一 當前年的月統計 select b.number as month sum a.a4012 shouru,sum a.a4011 feiyong,sum a.a4012 a4011 lirun from a040a001 a right join select number...

統計 Oracle按周統計(詳細)

建立表 test cteate table test id number not null,modifiedtime date not null 按周統計 select to char t.modifiedtime,yyyy year,to char t.modifiedtime,iw time,c...