这个用法在项目中用了好几次了,所以在此记录下来。
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
这个用法在项目中用了好几次了,所以在此记录下来。
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