2010-10-31 124 views
2

select count(distinct id) from svn where name='ant' and type='Bug'我可以將這2個簡單查詢合併爲一個查詢嗎?

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

是否有可能將它們合併成一個單一的查詢可能減少執行時間相比單獨運行呢?

感謝您的回答。

回答

4

是的,你可以通過使用組:

SELECT type, count(distinct id) AS cnt 
FROM svn 
WHERE name = 'ant' 
AND type IN ('Feature', 'Bug') 
GROUP BY type 
+0

喋喋不休!天哪,我不敢相信我沒有想到這一點。我想有時候,當解決方案非常簡單時,你只是想在更高的層次上進行思考。非常感謝。 – Gaurav 2010-10-31 18:18:27