17,090
社区成员
发帖
与我相关
我的任务
分享
select person
from(
select person,count(*) cnt,'今天' flag
from table_name
where create_date = trunc(sysdate)
group by person
union all
select person,count(*) cnt,'本周' flag
from table_name
where create_date in (trunc(sysdate)-to_char(sysdate,'d')+2+level-1 from dual connect by level <= 7)
group by person
union all
select person,count(*) cnt,'本月' flag
from table_name
where create_date in (select trunc(sysdate,'mm')+level-1 from dual connect by level <= last_day(trunc(sysdate,'mm'))-trunc(sysdate,'mm')+1)
group by person
union all
select person,count(*) cnt,'本年' flag
from table_name
where trunc(create_date,'year') = trunc(sysdate,'year')
group by person
select person,count(*) cnt,'系统至今' flag
from table_name
group by person
)
pivot(sum(cnt) for flag in('今天','本周','本月','本年','系统至今')
select person,count(*),'今天' type
from table_name
where create_date = trunc(sysdate)
group by person
union all
select person,count(*),'本周' type
from table_name
where create_date in (trunc(sysdate)-to_char(sysdate,'d')+2+level-1 from dual connect by level <= 7)
group by person
union all
select person,count(*),'本月' type
from table_name
where create_date in (select trunc(sysdate,'mm')+level-1 from dual connect by level <= last_day(trunc(sysdate,'mm'))-trunc(sysdate,'mm')+1)
group by person;