这是我尝试过的,但无法正常工作
SELECT d.deptno,d.dname
COUNT('e.empno') "number of employees"
FROM dept,emp
WHERE d.deptno = e.deptno
GROUP BY d.deptno,d.dname
非常感谢任何帮助谢谢
这是我尝试过的,但无法正常工作
SELECT d.deptno,d.dname
COUNT('e.empno') "number of employees"
FROM dept,emp
WHERE d.deptno = e.deptno
GROUP BY d.deptno,d.dname
非常感谢任何帮助谢谢
在 sql-server 中它会像
SELECT d.deptno,d.dname,
COUNT(e.empno) as number_of_employees
FROM dept d,emp e
WHERE d.deptno = e.deptno
GROUP BY d.deptno,d.dname
the error occurs when you undefined the instance of the table used
以防万一更优化
SELECT d.deptno,d.dname, COUNT(e.empno) as number_of_employees FROM dept d join emp e on d.deptno = e.deptno GROUP BY d.deptno,d.dname
好的,您有一些语法错误:
PS在这里假设T-SQL / MS SQL Server。
在我看来,您可能正在使用 Oracle,在这种情况下,修复相当简单:
SELECT d.deptno, d.dname, count(e.empno) "number of employees"
FROM dept d, emp e
WHERE d.deptno = e.deptno
GROUP BY d.deptno, d.dname
您需要明确告诉数据库别名所指的内容。错误消息可能提到了无效/缺失的标识符“d”,这意味着它不知道那是什么。
尝试
SELECT d.department_id,
d.department_name,
COUNT(e.employee_id) as number_of_employees
FROM departments d
JOIN employees e
on d.department_id = e.department_id
GROUP BY d.department_id, d.department_name;