mysql - 有条款问题

标签 mysql

使用 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/

相关文章:

php - 对于某些参数仅触发一次计划任务

mysql - 如何知道列的数据类型?

mysql - 如何在 TypeORM 中使用具有自动递增 id 列的表进行级联插入

mysql - phpmyadmin 将 CSV 导出到 Excel 会删除数据

MySql 小于带有 Group By 子句的数量

mysql - SQL:在groupby数据中查找前n个

mysql - 戈朗 : How to validate a MySQL timestamp string

mysql - SQL:如何返回不存在的行?

if语句的mysql语法问题

php 嵌套类别生成错误的输出