byte-jie 2022-02-15 23:55 采纳率: 100%
浏览 143
已结题

遇到一个MYSQL错误

要求:分组查询部门总人数

img

### 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:

  • 写回答

4条回答 默认 最新

  • CSDN专家-sinJack 2022-02-16 00:06
    关注

    Sql都写错了。用子查询就行了,不用判断是否为空,而且子查询时也不用分组,本来就是根据部门id进行查询的。

    select d.id,d.name,(select count(1) from tb_user u
    where u.department_id = d.id) 部门总人数 
    from tb_department d
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 3月7日
  • 已采纳回答 2月27日
  • 创建了问题 2月15日