我有一个名为 ProjectRessources 的表,其中包含以下数据:
+-----------+------------+---------+-----------+
| projectId | employeeId | nbHours | wageHours |
+-----------+------------+---------+-----------+
| 1 | 1876 | 500 | 65 |
| 1 | 4354 | 2000 | 31 |
| 2 | 2231 | 250 | 55 |
| 3 | 1212 | 3000 | 35 |
| 3 | 1876 | 2000 | 35 |
| 3 | 2231 | 500 | 65
我必须查询从事多个项目的员工才能获得以下信息:
+------------+----------------+
| employeeId | nbProjects |
+------------+----------------+
| 1876 | 2 |
| 2231 | 2 |
+------------+----------------+
我努力了
SELECT DISTINCT employeeID,projectID
FROM ProjectRessources
WHERE COUNT(projectID) >1;
但我在使用 COUNT 时收到错误 1111
ERROR 1111 (HY000): Invalid use of group function
然后我尝试了这样的事情
SELECT DISTINCT
employeeId ,
COUNT(projectId) as nbProjects
From ProjectRessources
WHERE nbProjects >1;
但后来我得到以下错误
ERROR 1054 (42S22): Unknown column 'nbProjects' in 'where clause'
请帮助,任何反馈表示赞赏。请注意,我不允许使用 GROUP BY 进行查询。