尝试编写一个查询,使用不同的情况计算多个事物

时间:2014-10-12 22:49:59

标签: mysql sql

我需要帮助我正在尝试编写一个查询,在不同情况下计算多个事物。 到目前为止,这是我能够进行单独查询的地方,但我想要做的就是将它们组合在一起

SELECT COUNT(*) AS "Marketing"
    FROM PROJECT
    WHERE Department = 'Marketing';

SELECT COUNT(*) AS "Number of Finance"
    FROM PROJECT
    WHERE Department = 'Finance';

SELECT COUNT(*) AS "Number of Accounting"
    FROM PROJECT
    WHERE Department = 'Accounting';

1 个答案:

答案 0 :(得分:2)

尝试GROUP BY

SELECT Department, COUNT(*) AS Count
FROM PROJECT
WHERE Department IN  ('Marketing','Finance','Accounting')
GROUP BY Department