1

使用上一个问题中的 Employee 和 Department 表

我正在尝试建立另一个组合表,显示在总部和研究部门工作的员工人数。

到目前为止,我已经尝试过了,但是在我的 having 子句中不断出现错误。有什么建议么?

mysql> select e.fname, d.dname
    -> from department d
    -> inner join employee e on e.dno = d.dnumber
    -> group by e.fname
    -> having d.dname='Headquarters','Research';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
use near ''Research'' at line 5
mysql> select e.fname, d.dname
    -> from department d
    -> inner join employee e on e.dno = d.dnumber
    -> group by e.fname
    -> having d.dname=1,5;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
use near '5' at line 5
4

1 回答 1

2

INWHERE子句中使用。

SELECT...
FROM...
WHERE d.dname IN ('Headquarters','Research')
GROUP BY...
于 2012-12-09T01:45:09.510 回答