gpt4 book ai didi

Mysql连接两个表

转载 作者:行者123 更新时间:2023-11-29 09:26:37 24 4
gpt4 key购买 nike

现在我有这两张表

doctor_id 及其预约计数

doctor_id and their appointment count

以及医生姓名和他/她的科室名称

doctor name and his/her department name

我需要计算每个部门的约会,知道如何连接这两个表吗?

最佳答案

只需加入所有表格并更改分组即可。

SELECT d.name AS department, COUNT(r.d_id) AS appointment_count
FROM departments AS d
JOIN userdelprel AS ud ON d.dept_id = ud.dept_id
JOIN users AS u ON u.u_id = ud.u_id
LEFT JOIN roomreservations AS r ON r.d_id = u.u_id
WHERE u.role_id = 2
GROUP BY d.dept_id

关于Mysql连接两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59507246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com