我可以将这两个简单的查询合并到一个查询中吗?

时间:2010-10-31 18:13:44

标签: sql mysql

select count(distinct id) from svn where name='ant' and type='Bug'

select count(distinct id) from svn where name='ant' and type='Feature'

与单独运行相比,是否可以将它们组合成一个可能缩短执行时间的查询?

感谢您的回答。

1 个答案:

答案 0 :(得分:4)

是的,你可以使用group by:

SELECT type, count(distinct id) AS cnt
FROM svn
WHERE name = 'ant'
AND type IN ('Feature', 'Bug')
GROUP BY type
相关问题