1
我想從我的MySQL表中獲取一些統計信息,並希望將它保留爲單個查詢。只是不知道如何(或者甚至可能)。我有兩個疑問:將同一表中的查詢合併爲一個查詢
SELECT COUNT(*) AS `accept`
FROM `status`
WHERE `groupID` IN (98779,98780)
AND `group` = 'order'
AND `status` = 'accept'
和
SELECT COUNT(*) AS `price`
FROM `status`
WHERE `groupID` IN (98779, 98780)
AND `group` = 'quotation'
AND (`status` = 'final' OR `status` = 'manualprice')
我最好的建議是,他們在一個單一的SELECT
這樣的組合:
SELECT
(SELECT COUNT(*) AS `accept`
FROM `status`
WHERE `groupID` IN (98779, 98780) AND `group` = 'order' AND `status` = 'accept') AS accept,
(SELECT COUNT(*) AS `price`
FROM `status`
WHERE `groupID` IN (98779, 98780) AND `group` = 'quotation' AND (`status` = 'final' OR `status` = 'manualprice')) AS price
有沒有更好的辦法?
這是非常聰明的......這麼好有更多的學習。我能夠將我的查詢優化10倍。非常感謝! –