使用 previous question 中的员工表和部门表
我正在尝试构建另一个组合表,显示在总部和研究部门工作的员 worker 数。
到目前为止,我已经尝试过了,但在我的 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
最佳答案
在 WHERE
子句中使用 IN
。
SELECT...
FROM...
WHERE d.dname IN ('Headquarters','Research')
GROUP BY...
关于mysql - 有条款问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13783872/