这个用法在项目中用了好几次了,所以在此记录下来。
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
时间: 2024-10-20 09:04:12