我有两个问题:
SELECT `type`, COUNT(`id`) AS 'type' FROM `items` WHERE `post` = `id` GROUP BY `type`;
SELECT `type`, COUNT(`post`!=`id`) AS 'posts' FROM `items` GROUP BY `type`;
有没有办法在一个查询中创建它?
答案 0 :(得分:1)
这样的事情
SELECT `type`,
COUNT(`post`=`id`),
COUNT(`post`!=`id`) AS 'posts'
FROM `items`
GROUP BY `type`;