使用 MAX 和 COUNT 从 3 个不同的表中生成报告?
我有一个包含患者、医生、橱柜和就诊信息的数据库。
患者(id_pac、FirstName、LastName)
医生(id_med、FirstName、LastName、专业)
内阁(id_cab、姓名)
可视化(id_viz、Date_viz) , Medic_id,Patient_id, Cabinet_id)
一名医生可以在不同的日期、在不同的柜子上拜访不同的患者。
我需要在一份报告中找到(使用子查询或连接?,但不使用中间表或视图):
- 包含医生的完整姓名的一列:CONCAT(FirstName,' ', LastName) (DISTINCT),
- 一列包含医生就诊次数最多的内阁名称 和 3.一栏显示该柜子的访问次数。
我试图弄清楚如何获取这些信息,但我所能拥有的只是 他就诊的每个柜子的医生名单,以及每个柜子的总就诊次数:((
I have a database with patients, doctors, cabinets and visits.
Patients (id_pac, FirstName, LastName)
Doctors (id_med, FirstName, LastName, Speciality)
Cabinets (id_cab, Name)
Vizits (id_viz, Date_viz, Medic_id,Patient_id, Cabinet_id)
One doctor can make visits on different patients, on different cabinets, on different dates.
I need to find out (with a subquery or with a join ? , but NOT with intermediary tables or views), in one report :
- one column with the doctor's complete name : CONCAT(FirstName,' ',LastName) (DISTINCT),
- one column with the cabinet name in which the doctor was having the biggest number of visits
and
3.one column with the number of visits for this cabinet.
I have tried to figure out how can i get this information, but all what I can have is
the list of doctors with every cabinets in which he was having visits, with the total number of visits / cabinet :((
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我试图更好地理解这个子查询,我找到了另一种方法(我认为是一种简单的方法)。代码是:
@ypercube:如果您发现一些差异,请告诉我,因为了解我是否忘记或逃避某些内容很重要。
I was trying to better understand this subquery and I found an another way (a simple one i believe). The code is :
@ypercube : Please let me know if you see some differences , because it's important to see if I forgot or escape something.