日期:2014-05-17 浏览次数:20710 次
--帮你整理了下代码 试试 select k.patient_id , k.visit_id , k.treat_result , l.patient_id , l.visit_id , l.dept_discharge_from , l.inp_no , l.doctor_in_charge , l.attending_doctor , m.patient_id , m.visit_id , n.dept_code , n.patient_id , n.visit_id , o.dept_code from ( select distinct c.* from ( select b.patient_id , b.visit_id , b.TREAT_RESULT from diagnosis a inner join diagnosis b on ( a.patient_id = b.patient_id and a.visit_id = b.visit_id ) where a.TREAT_RESULT = '死亡' ) c ) k left join pat_visit l on ( k.patient_id = l.patient_id and k.visit_d = l.visit_id ) left join pat_master_index m on ( k.patient_id = m.patient_id and k.visit_id = m.visit_id ) left join mr_on_line n on ( k.patient_id = n.patient_id and k.visit_d = n.visit_id )
------解决方案--------------------
少加了几个逗号
SELECT k.patient_id, k.visit_id, k.treat_result, l.patient_id, l.visit_id, l.dept_discharge_from, l.inp_no, l.doctor_in_charge, l.attending_doctor, m.patient_id, m.visit_id, n.dept_code, n.patient_id, n.visit_id, o.dept_code FROM ( SELECT DISTINCT c.* FROM ( SELECT b.patient_id , b.visit_id , b.TREAT_RESULT FROM diagnosis a JOIN diagnosis b ON ( a.patient_id = b.patient_id AND a.visit_id = b.visit_id ) WHERE a.TREAT_RESULT = '死亡' ) c ) k LEFT JOIN pat_visit l ON ( k.patient_id = l.patient_id AND k.visit_d = l.visit_id ) LEFT JOIN pat_master_index m ON ( k.patient_id = m.patient_id AND k.visit_id = m.visit_id ) LEFT JOIN mr_on_line n ON ( k.patient_id = n.patient_id AND k.visit_d = n.visit_id )
------解决方案--------------------
看到都脑袋痛
------解决方案--------------------
别名表 k可改改,不需要再嵌套
select k.patient_id,k.visit_id,k.treat_result, l.patient_id,l.visit_id,l.dept_discharge_from,l.inp_no,l.doctor_in_charge,l.attending_doctor, m.patient_id,m.visit_id, n.dept_code,n.patient_id,n.visit_id, o.dept_code from (select DISTIN