这个错在哪里 请问
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)
[解决办法]
--帮你整理了下代码 试试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_codefrom ( 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_codeFROM ( 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 ) kLEFT JOIN pat_visit lON ( k.patient_id = l.patient_id AND k.visit_d = l.visit_id )LEFT JOIN pat_master_index mON ( k.patient_id = m.patient_id AND k.visit_id = m.visit_id )LEFT JOIN mr_on_line nON ( 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_codefrom(select DISTINCT 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='死亡' )kleft join pat_visit l on k.patient_id=l.patient_id and k.visit_d=l.visit_idleft join pat_master_index m on k.patient_id=m.patient_id and k.visit_id=m.visit_idleft join mr_on_line n on k.patient_id=n.patient_id and k.visit_d=n.visit_id