首页 > 代码库 > sum case when 条件筛选

sum case when 条件筛选

这个用法在项目中用了好几次了,所以在此记录下来。

SELECT
c.*, sum(
CASE
WHEN (a. STATUS = 1 OR a. STATUS IS NULL) THEN
1
ELSE
0
END
) AS articleNum,
SUM(a.read_num) AS readNum
FROM
sky_information_category c

 

附上一张照片。。来源 http://database.51cto.com/art/201107/279732.htm

技术分享

 

sum case when 条件筛选