複数の部門で働いている従業員の数(金額)を表示するクエリを見つけようとしています。テーブル名とフィールドは次のとおりです。
Employee
(id_employee、employee_name、salary)Department
(id_dept、dept_name、予算)Department_Employee
(id_employee、id_dept、workhours_percentage)
Department_Employee テーブルの内容が
id_employee id_dept workhours_percentage
----------- ------- --------------------
0001 03 100
0001 04 50
0001 05 60
0002 05 60
0002 09 90
0003 08 80
0004 07 80
0005 06 60
0006 05 70
0007 04 75
0008 10 95
0009 02 25
0010 01 40
適切なクエリを使用すると、結果は 2 (従業員) になるはずです。これは、2 人の従業員が複数の部門で働いているためです。
- 従業員 0001 は 3 つの部門で働いています
- 従業員 0002 は 2 つの部門で働いています
次のクエリで試しました
SELECT COUNT(DISTINCT id_employee)
FROM Department_Employee
GROUP BY id_employee
HAVING COUNT(id_employee)>1
しかし、結果は正しくありません。
私を助けてください。
ありがとう。