SQL server 和 Oracle 中列转行的小操作
程序员文章站
2022-06-05 08:06:27
Oracle: create table zjhis.mz_zdxx_zl as select a.sfsb, wm_concat(a.zdmc) as 诊断 from zjhis.mz_zdxx a group by a.sfsb 直接可以使用 wm_concat 函数 SQl SERVER : ......
Oracle:
create table zjhis.mz_zdxx_zl
as
select a.sfsb,
wm_concat(a.zdmc) as 诊断 from zjhis.mz_zdxx a
group by a.sfsb
直接可以使用 wm_concat 函数
SQl SERVER :
select t.patient_id,
t.times,
[ values ] = stuff((select ',' + icd_name
from sx2017.dbo.mz_visit_diagnose
where patient_id = t.patient_id
and times = t.times
for xml path('')), 1, 1, '')
from sx2017.dbo.mz_visit_diagnose t
group by patient_id, times
patient_id, times 为关连字段
t.times,
[ values ] = stuff((select ',' + icd_name
from sx2017.dbo.mz_visit_diagnose
where patient_id = t.patient_id
and times = t.times
for xml path('')), 1, 1, '')
from sx2017.dbo.mz_visit_diagnose t
group by patient_id, times
patient_id, times 为关连字段
上一篇: 不甘落后 索尼将目光瞄准无人驾驶领域
下一篇: 现在的小学生太有才了