sql count中加条件

一般的,我们会在where, 或者 having中加条件,count中只是某个字段

今天看到另外一种写法,不知道性能怎么样

select 

count(  case    when xxx>10 and yyy<99 then bbb else null end)  cm1,

count(  case    when xxx>20 and yyy<1 then ccc  else null end)  cm2

from xxxx

基本原理是 使用了数据库count(null)时返回的是0 count(非null)返回是1

@Flink SQL

猜你喜欢

转载自www.cnblogs.com/yszzu/p/10430483.html
今日推荐