要求:分组查询部门总人数
### Cause: java.sql.SQLSyntaxErrorException: 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 '*)
from tb_user u
where u.department_id = ' at line 3
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException:
Sql都写错了。用子查询就行了,不用判断是否为空,而且子查询时也不用分组,本来就是根据部门id进行查询的。
select d.id,d.name,(select count(1) from tb_user u
where u.department_id = d.id) 部门总人数
from tb_department d
sql语法错误,请把你的完整sql贴出来
IFNULL() 函数语法格式为:IFNULL(expression, alt_value), 你在使用时候, 你的ifnull后面只需要一个小括弧就可以了, 比如: ifnull(select count(*) from student , 9)
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!