• oracle中行列转换,max,listagg使用


    需求:求门诊开甲功三项的病人的基本信息与化验结果的数据,

    自己的写法是:

    select a.sampleno,a.patientname,a.patientid ,listagg(testresult,',')
    within GROUP (order by testresult desc) abc
    from bslis.l_patientinfo a,bslis.l_testresult b where a.sampleno =b.sampleno and a.examinaim='甲功三项'
    group by a.sampleno ,a.patientname,a.patientid

    这上面是lis的检验结果

    lis中同一个样本号码对应三个testid然后是结果是分三条显示的,所以用了listagg然后就被动用了group by,所以打算lis与his信息union的话就比较难了

    =======================================

    select a.brid,mzhm,a.brxm,a.sfzh, xzz_qtdz, b.yz_z,b.yz_t, age,patientid from ms_brda a, ys_mz_jzls b ,l_lis_sqd c,ms_yj01 d
    where a.brid=b.brbh and a.mzhm=c.patientid and c.doctrequestno=d.sqdh and d.jzxh=b.jzxh
    and (b.yz_z is not null or b.yz_t is not null) and c.examinaim like '甲功三项' and c.bed_no is null

     这是his的病人基本信息,lis与his都有patientid,打算Union ,上面提到union很难实现

     =============================================================================

    select brid,mzhm,brxm,sfzh,csny, xzz_qtdz,yz_z,yz_t,age,patientid,
    max(FT3) FT3,max(FT4) FT4,max(TSH) TSH from (

    select a.brid,mzhm,a.brxm,a.sfzh,csny, xzz_qtdz, b.yz_z,b.yz_t, c.age,c.patientid,
    f.testresult,f.testid,
    case when f.testid = 1111 then f.testresult else '' end FT3,
    case when f.testid = 1112 then f.testresult else '' end FT4,
    case when f.testid = 1113 then f.testresult else '' end TSH
    from ms_brda a, ys_mz_jzls b ,l_lis_sqd c,ms_yj01 d ,
    bslis.l_jytmxx e,bslis.l_testresult f
    where a.brid=b.brbh and a.mzhm=c.patientid and
    c.doctrequestno=d.sqdh and d.jzxh=b.jzxh
    and (b.yz_z is not null or b.yz_t is not null) and
    c.examinaim like '甲功三项' and c.bed_no is null and
    e.sampleno = f.sampleno and c.doctrequestno = e.doctrequestno

    )t
    group by brid,mzhm,brxm,sfzh,csny, xzz_qtdz,yz_z,yz_t,age,patientid

    ========================

    上面的

    select a.brid,mzhm,a.brxm,a.sfzh,csny, xzz_qtdz, b.yz_z,b.yz_t, c.age,c.patientid, 
    f.testresult,f.testid,
    case when f.testid = 1111 then f.testresult else '' end FT3,
    case when f.testid = 1112 then f.testresult else '' end FT4,
    case when f.testid = 1113 then f.testresult else '' end TSH
    from ms_brda a, ys_mz_jzls b ,l_lis_sqd c,ms_yj01 d ,
    bslis.l_jytmxx e,bslis.l_testresult f
    where a.brid=b.brbh and a.mzhm=c.patientid and 
    c.doctrequestno=d.sqdh and d.jzxh=b.jzxh
    and (b.yz_z is not null or b.yz_t is not null) and 
    c.examinaim like '甲功三项' and c.bed_no is null and
    e.sampleno = f.sampleno and c.doctrequestno = e.doctrequestno 

     

  • 相关阅读:
    DFGUI之Event Binding
    webform--常用的控件
    ASP.NET aspx页面中 写C#脚本; ASP.NET 指令(<%@%>);
    LinQ操作
    什么是C# Lambda表达式?形如:p=>p.abc
    winform基础
    winform之2---messagebox用法
    winform 之1---窗体介绍
    HTML-答案检查&按钮倒计时
    HTML-字体逐渐显示
  • 原文地址:https://www.cnblogs.com/thomasbc/p/9710029.html
Copyright © 2020-2023  润新知