MySQL加入两个不同的选择

时间:2016-11-03 09:50:17

标签: mysql select join

我能以某种方式加入这两个查询吗?:

SELECT SUM(count) AS sum_count FROM prescription 
WHERE dep_id='4' AND hist_id='?' AND med_id='?' AND status='active'

SELECT * FROM prescription p 
JOIN medicament_list ml ON ml.id=p.med_id 
WHERE dep_id='4' AND hist_id='?' AND med_id='?' AND status='active'

1 个答案:

答案 0 :(得分:0)

在这里找到解决方案:

SELECT medicament_list.med_name, SUM(prescription.count) AS sum_count FROM prescription JOIN medicament_list ON medicament_list.id=prescription.med_id WHERE dep_id='4' AND hist_id='?' AND med_id='?' AND status='active'