MySQL中如何创建统计图书类别的MySQL语句?
发布网友
发布时间:2022-04-14 07:03
我来回答
共1个回答
热心网友
时间:2022-04-14 08:33
SELECT SUM(male) AS male, SUM(female) AS female, SUM(middle) AS middle
FROM (
SELECT 0 AS name,
SUM(IF(name = 'male', 1, 0)) AS male,
SUM(IF(name = 'female', 1, 0)) AS female,
SUM(IF(name = 'middle', 1, 0)) AS middle
FROM a GROUP BY name
) AS t
GROUP BY t.name
写的有点复杂。