首页 > 技术文章 > sql count中加条件

yszzu 2019-02-25 13:42 原文

一般的,我们会在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

推荐阅读