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

<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
)




阅读更多
文章标签: mysql
个人分类: mysql
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭