两个查询优化

时间:2011-10-10 04:07:19

标签: mysql

我有两个问题:

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`;

有没有办法在一个查询中创建它?

1 个答案:

答案 0 :(得分:1)

这样的事情

SELECT  `type`, 
        COUNT(`post`=`id`), 
        COUNT(`post`!=`id`) AS 'posts' 
FROM    `items` 
GROUP BY    `type`;