我正在尝试从我的 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
有没有更好的办法?