[SQL] 请教一下 count里面有case when 一般情况下啥时候用

http://www.itpub.net/forum.php?mod=viewthread&tid=1810967

问题:

比如 count(case when  pday_id=${deal_date}   then 1  end)  我有点想不明白具体什么情况下count() 这个小括号里面还要用case when  大家做BI统计的时候一般什么情况用啊  
还有个问题 select case when actionname in ('haha','heihei') then '-1' else case when operateType='1' and restype='3' then resid   一般case when 是原来的表里没有的字段  我们人为构造的一个字段  这个sql语句的意识是当action这个字段是'haha'或者'heihei'时 我们case when 这个字段是-1  当 operateType='1' and restype='3' 这个构造的case when 字段是resid这个字段的值    那 同时不符合这两种情况下的我们构造的case when这个字段的值是多少啊  请教各位了  谢谢

 then 后面的和 else 后面的数据类型要一致

猜你喜欢

转载自www.cnblogs.com/yadongliang/p/9120816.html