找到至少参与过两个项目的所有员工

时间:2016-01-16 01:35:41

标签: mysql sql select

表:ProjectRessources

IDPRoject  IDEmployee  NumHours   PricePerHr
1          1876       500        65
1          4354       2000       31
2          2231       250        55
3          2231       500        65
3          1212       3000       35
3          1876       2000       35

我只提出以下研究语法,但无法计算如何过滤仅指示2231和1876:

SELECT IDEmployee, COUNT (*) AS ‘Number of Projects’
FROM Projectressources
GROUP BY IDEmployee;

1 个答案:

答案 0 :(得分:3)

你朝着正确的方向前进。您遗失的部分是having子句,允许您过滤聚合表达式,例如count(*)

SELECT   IDEmployee, COUNT (*) AS ‘Number of Projects’ 
FROM     Projectressources
GROUP BY IDEmployee
HAVING   COUNT(*) > 1 -- Here!