有条款问题

时间:2012-12-09 01:42:34

标签: mysql

使用previous question

中的员工和部门表

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

到目前为止,我已经尝试了这个,但是在我的条款中不断出错。有什么建议吗?

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

1 个答案:

答案 0 :(得分:2)

IN子句中使用WHERE

SELECT...
FROM...
WHERE d.dname IN ('Headquarters','Research')
GROUP BY...