sql语句中case的写法问题

真老狼 2008-09-25 05:58:57
select sum(case a.proc_stat when 'E' then 1 else 0 end)
from cpnst_appl a
where a.cpnst_caserpt_id in
……

现在想把when 'E' 写成一个范围的形式
如proc_stat 在20080101到20080909之间的 该怎么写
when between?
...全文
66 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wufongming 2008-09-26
  • 打赏
  • 举报
回复
select sum(case when a.proc_stat between to_date('20080101','yyyymmdd') and to_date('20080909','yyyymmdd') then 1 else 0 end)
from cpnst_appl a
where a.cpnst_caserpt_id in
zhuyx808 2008-09-26
  • 打赏
  • 举报
回复
case when **** then ** when **** then ** else * end

**** 就是条件表达式,你between and 或者别的什么都可以的啦
真老狼 2008-09-26
  • 打赏
  • 举报
回复
可以,谢了
真老狼 2008-09-25
  • 打赏
  • 举报
回复
不是放在where里作为条件的,楼上的我试试
pangzihuihui 2008-09-25
  • 打赏
  • 举报
回复
select sum(case when a.proc_stat between to_date('20080101','yyyymmdd') and to_date('20080909','yyyymmdd') then 1 else 0 end)
from cpnst_appl a
where a.cpnst_caserpt_id in
……

应该可以的~~~
bruni 2008-09-25
  • 打赏
  • 举报
回复
why not set the criteria in the where clause directly?
a.proc_stat between(1, 2)?

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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