select applyNo,MAX( createdAt)astimefrom recall_record where applyNo in(select applyNo from recall_case WHERE updatedAt >'2022-11-29 22:00:00'and updatedAt <'2022-11-29 22:05:00')GROUPBY applyNo
行转列
selectsum(decode(name,'action',num)) action_,sum(decode(name,'alarm', num)) alarm,sum(decode(name,'di',num)) di,sum(decode(name,'list',num)) list from(select'action' name,count(1) num
from
SG_RPAM_PRO_ACTION
unionallselect'alarm' name,count(1) num
from
SG_RPAM_PRO_ALARM
unionallselect'di' name,count(1) num
from
SG_RPAM_PRO_DI
unionallselect'list' name,count(1) num from SG_RPAM_PRO_RECORD_LIST)
按天检索数据无数据补0
select
t1.date_ref,casewhen t2.num isnullthen0else t2.num endas num
from(select to_char(to_date('2017-11-09','yyyy-mm-dd')+level-1,'yyyy-mm-dd') date_ref from sysdba.sysdual connectbylevel<8)as t1
leftjoin(selectcount(1) num,
to_char(to_date(record_time,'yyyy-mm-dd'),'yyyy-mm-dd') date_act
from
SG_RPAM_PRO_RECORD_LIST
where
record_time between'2017-11-09'and'2017-11-15'groupby
to_char(to_date(record_time,'yyyy-mm-dd'),'yyyy-mm-dd'))as t2
on
t1.date_ref=t2.date_act