关闭

mysql查询结果合并去重、合并全部

标签: mysql
965人阅读 评论(0) 收藏 举报
分类:
<span style="font-family: Arial, Helvetica, sans-serif;">SELECT doctor_id,doctor_name,doctor_position,COUNT(*) amount</span>
FROM
(
(SELECT d.doctor_id,d.doctor_name,d.doctor_position
FROM doctor_info d 
LEFT JOIN hospitalized h ON d.doctor_id=h.doctor_id)
UNION ALL
(SELECT d.doctor_id,d.doctor_name,d.doctor_position
FROM doctor_info d 
LEFT JOIN u_outpatient o ON o.doctor_id = d.doctor_id
)
UNION ALL
(
SELECT d.doctor_id,d.doctor_name,d.doctor_position
FROM doctor_info d 
LEFT JOIN med_follow f ON f.doctor_id = d.doctor_id
)
) dd
GROUP BY doctor_name
ORDER BY amount DESC

合并全部

======================================================

合并去重

(SELECT d.doctor_id,d.doctor_name,d.doctor_position
FROM doctor_info d 
LEFT JOIN hospitalized h ON d.doctor_id=h.doctor_id)
UNION
(SELECT d.doctor_id,d.doctor_name,d.doctor_position
FROM doctor_info d 
LEFT JOIN u_outpatient o ON o.doctor_id = d.doctor_id
)
UNION
(
SELECT d.doctor_id,d.doctor_name,d.doctor_position
FROM doctor_info d 
LEFT JOIN med_follow f ON f.doctor_id = d.doctor_id
)




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:19424次
    • 积分:551
    • 等级:
    • 排名:千里之外
    • 原创:32篇
    • 转载:23篇
    • 译文:0篇
    • 评论:0条
    文章分类