怎么改这个SQL语句

520NET 2006-08-16 09:58:30
select T.ZONE as tID ,sum(case when A.PSC_ID is not null then 1 else 0 end) as tTotal from tb_psr_check A
right join (
select '00' as ZONE from tb_psr_check
union select '01' from tb_psr_check
union select '02' from tb_psr_check
union select '03' from tb_psr_check
。。。。。。。。。。。。。。。。。。 (省略)
union select '23' from tb_psr_check ) T
on substr(T.ZONE,1,2)=to_char(psc_check_time,'HH24') group by T.Zone
显示结果如下:
TID TTOTAL
00 3
01 4
02 2
03 5
04 1
05 2
。。。(省略)
23 3
我想添加psc_check_time大于某个时间段,显示结果还是像上面一样,请问怎么改?谢谢
...全文
123 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
feng2 2006-08-16
  • 打赏
  • 举报
回复
select T.ZONE as tID ,count(A.PSC_ID) as tTotal from tb_psr_check A
right join (
select '00' as ZONE from tb_psr_check
union select '01' from tb_psr_check
union select '02' from tb_psr_check
union select '03' from tb_psr_check
...................................
union select '23' from tb_psr_check ) T
on substr(T.ZONE,1,2)=to_char(psc_check_time,'HH24')
and t.zone > to_char(&date,'hh24') -- 输入时间
group by T.Zone
xiaoxiao1984 2006-08-16
  • 打赏
  • 举报
回复
select T.ZONE as tID ,count(A.PSC_ID) as tTotal from tb_psr_check A
right join (
select '00' as ZONE from tb_psr_check
union select '01' from tb_psr_check
union select '02' from tb_psr_check
union select '03' from tb_psr_check
...................................
union select '23' from tb_psr_check ) T
on substr(T.ZONE,1,2)=to_char(psc_check_time,'HH24')
and a.psc_check_time >= to_date('2006-8-16 00:00:00','yyyy-mm-dd hh24:mi:ss')
group by T.Zone
不好意思,上一个写错了
520NET 2006-08-16
  • 打赏
  • 举报
回复
我想添加时间只是判断大于当天的某个时间,不统计过去的数据
feng2 2006-08-16
  • 打赏
  • 举报
回复
..........
where a.psc_check_time >= to_date('2006-8-16 00:00:00','yyyy-mm-dd hh24:mi:ss')
..........

------------------------
..........
where a.psc_check_time >= to_date('2002-8-16 00:00:00','yyyy-mm-dd hh24:mi:ss')
..........
520NET 2006-08-16
  • 打赏
  • 举报
回复
select T.ZONE as tID ,count(A.PSC_ID) as tTotal from tb_psr_check A
right join (
select '00' as ZONE from tb_psr_check
union select '01' from tb_psr_check
union select '02' from tb_psr_check
union select '03' from tb_psr_check
...................................
union select '23' from tb_psr_check ) T
on substr(T.ZONE,1,2)=to_char(psc_check_time,'HH24')
where a.psc_check_time >= to_date('2006-8-16 00:00:00','yyyy-mm-dd hh24:mi:ss')
group by T.Zone
显示结果没有任何数据
xiaoxiao1984 2006-08-16
  • 打赏
  • 举报
回复
select T.ZONE as tID ,count(A.PSC_ID) as tTotal from tb_psr_check A
right join (
select '00' as ZONE from tb_psr_check
union select '01' from tb_psr_check
union select '02' from tb_psr_check
union select '03' from tb_psr_check
......
union select '23' from tb_psr_check ) T
on substr(T.ZONE,1,2)=to_char(psc_check_time,'HH24')
where a.psc_check_time >= &sdate
group by T.Zone

17,089

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧