case when then else end数据统计

今天用case when then else end 做了个数据统计,有一个A表,有id,status这2个字段,现在需要统计id的数目和status>5的id的数目;

用sql语句的写法:

select count(id),count(case when status>5 then 1 else null end)

from A

ok啦

原文地址:https://www.cnblogs.com/lan-writenbook/p/4756094.html