Oracle實現按季度劃分,並計數

2021-07-24 20:00:51 字數 1272 閱讀 6285

表結構如下

create

table tbl_test1(

tbl_username varchar(50),

tbl_tbname varchar(50),

tbl_zhixing varchar(50)

)

具體樣式– info表

tables

name

time

資源管理表

管理員1

2016-05-23

資源管理表

管理員2

2016-05-13

資源管理表

管理員1

2016-02-23

多個人在不同時間操作這個表,time為操作表的時間,name為人名,tables為表名。
按操作的時間進行分組,劃分成季度,統計每個人各個季度操作這個表的次數
具體實現
select to_char(to_date(time,'yyyy-mm-dd'),'yyyy-q')  time,

count(case

when to_char(to_date(time,'yyyy-mm-dd'),'q')=1

then name end) s1,

count(case

when to_char(to_date(time,'yyyy-mm-dd'),'q')=2

then name end) s2,

count(case

when to_char(to_date(time,'yyyy-mm-dd'),'q')=3

then name end) s3,

count(case

when to_char(to_date(time,'yyyy-mm-dd'),'q')=4

then name end) s4,

name name

from tbl_test1

group

by to_char(to_date(time,'yyyy-mm-dd'),'yyyy-q'),name

order

by to_char(to_date(time,'yyyy-mm-dd'),'yyyy-q')

其中time為varchar型 如果為date型就直接to_char就可以執行

日期格式

日期格式

sql年-月-日

yyyy-mm-dd

年-季度

yyyy-q

統計 Oracle按季度統計(詳細)

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

整數劃分的遞迴實現演算法,並輸出所有劃分

整數劃分的遞迴實現演算法,可進一步考慮輸出所有劃分 include using namespace std int integerdivision int n,int m 得到劃分數 void print int sum,int k,int prio 輸出所有劃分 int a 將這兩個資料設為全域性...

自定義圓形按鈕並實現按下狀態

首先在drawable 檔案下新建兩個 xml檔案 button ellipse tint green.xml 淺綠色的圓角 button ellipse green.xml 綠色的圓角 兩個xml 都一樣,下面是 自行修改填充顏色。填充顏色就是不同的按下顏色 以上操作完成後,在新建乙個 butto...