以下是我的表格:
SELECT * FROM DEPARTMENT;
DEPTNO DNAME LOC
---------- -------------------- --------------------
10 SWIFT WOLVER WOLVERHAMPTON
20 SWIFT BIR BIRMINGHAM
30 SWIFT MAN MANCHESTER
40 SWIFT LON LONDON
SELECT * FROM Employee;
EMPNO ENAME HIREDATE SAL DEPTNO
---------- ---------- ----------- ---------- ----------
1039 KING 17-NOV-1980 5000 10
1066 JONES 02-APR-1991 2975 20
1088 SCOTT 23-AUG-2016 3000 20
1276 ADAMS 26-SEP-2016 1100 20
1002 FORD 03-DEC-1991 3000 20
1169 SMITH 17-DEC-1990 800 20
1098 BLAKE 01-MAY-1981 2850 30
1099 ALLEN 20-FEB-1995 1600 30
1221 WARD 22-FEB-1994 1250 30
1454 MARTIN 28-SEP-1993 1250 30
1544 TURNER 08-SEP-1981 1500 30
1300 JAMES 03-DEC-1981 950 30
1482 CLARK 09-JUN-1989 2450 10
1134 MILLER 23-JAN-1985 1300 10
我在DEPTNO
(部门表)上有主键,在DEPTNO
(员工表)上有外键。
我编写了这个查询,该查询应该列出使用Group by
命令在每个部门上工作的雇主数量,但有些东西不起作用。当我尝试运行查询时,COUNT
上出现了问题,但无法找到确切的内容。任何人都可以帮我这个吗?
SELECT DEPARTMENT.DNAME,COUNT(EMPLOYEE,DEPTNO) AS Numberofemployers FROM EMPLOYEE
LEFT JOIN DEPARTMENT
ON DEPARTMENT.DEPTNO = EMPLOYEE.DEPTNO
GROUP BY DEPARTMENTNAME;
答案 0 :(得分:1)
这就是你想要的:
response = sock.recv(Constants.SKT_BUF_SIZE)
注释;
SELECT d.DNAME, COUNT(e.DEPTNO) AS Numberofemployees
FROM DEPARTMENT d LEFT JOIN
EMPLOYEE e
ON d.DEPTNO = e.DEPTNO
GROUP BY d.DNAME;
应该是DEPARTMENT
。LEFT JOIN
中的匹配记录。因此EMPLOYEE
。COUNT(e.DEPTNO)
通常只需要一个参数。你有多个参数。