如何更改MySQL选择查询的结果?

时间:2017-10-03 11:33:09

标签: mysql sql

我有以下查询

select pi.identifier, pn.given_name, pn.family_name,vt.name,  cn.name as diagnosis, v.date_created, e.encounter_id
from concept as c
inner join concept_name as cn on cn.concept_id = c.concept_id
inner join obs as o on o.value_coded = c.concept_id
inner join encounter as e on o.encounter_id = e.encounter_id
inner join visit as v on e.visit_id = v.visit_id
inner join patient as p on p.patient_id = v.patient_id
inner join person as per on per.person_id = p.patient_id
inner join person_name as pn on pn.person_id = per.person_id
inner join patient_identifier as pi on pi.patient_id = p.patient_id
inner join visit_type as vt on vt.visit_type_id = v.visit_type_id
where (c.class_id = 4 or c.class_id = 11)
and
v.voided = 0
and
cn.concept_name_type = 'FULLY_SPECIFIED'
and
date(v.date_created) between '2017-10-01' and '2017-10-02'

这给出了

Identifier  given_name  last_name   name    diagnosis   date_created    encounter_id
MMA001113   A   A   IGD BPJS    02-10-17 21:18  1804
MMA001113   A   A   IGD Confirmed   02-10-17 21:18  1805
MMA001113   A   A   IGD A07.0 (Balantidiasis)   02-10-17 21:18  1805
MMA001113   B   B   IGD UMUM    02-10-17 21:18  1806
MMA001113   B   B   IGD Confirmed   02-10-17 21:18  1807
MMA001113   B   B   IGD B07.0 (Balantidiasis)   02-10-17 21:18  1807

第1行和第3行包含“BPJS”和“Umum”,它实际上是应该应用于其他行的patient-type。我的预期结果如下所示

Identifier  given_name  last_name   name    diagnosis   date_created    encounter_id    patient_type
MMA001113   A   A   IGD Confirmed   02-10-17 21:18  1805    BPJS
MMA001113   A   A   IGD A07.0 (Balantidiasis)   02-10-17 21:18  1805    BPJS
MMA001113   B   B   IGD Confirmed   02-10-17 21:18  1807    UMUM
MMA001113   B   B   IGD B07.0 (Balantidiasis)   02-10-17 21:18  1807    UMUM

我可以从结果行中排除类型,但我需要将其作为结果列。

如何修改我的SQL查询以实现这一目标?

0 个答案:

没有答案