这是我尝试过的,无法让它工作
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
非常感谢任何帮助
答案 0 :(得分:1)
在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)为number_of_employees 来自dept d join emp e 在d.deptno = e.deptno GROUP BY d.deptno,d.dname
答案 1 :(得分:0)
好的,你有一些语法错误:
P.S。假设这里有T-SQL / MS SQL Server。
答案 2 :(得分:0)
在我看来,您可能正在使用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',这意味着它不知道那是什么。
答案 3 :(得分:0)
尝试
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;