zoukankan      html  css  js  c++  java
  • MYSQL中遇到的问题以及解决方法(四)排序后筛选+横转纵

    采集方式有KRK和YD

    将YD的数据和KRK的放在 一列,但是可能YD有两条,那么如何选择YD最新的一条和KRK结合起来呢?先筛选后横转纵

    -- KRK 和YD组合到一起
    select PatientID ,  Age, Sex, Height, Weight,OperatorID,BMI,
    max(case when KRKPPGFilePath is not null then KRKPPGFilePath else '' end) KRKPPGFilePath , 
    max(case when KRKPPGFilePath is not null then SBP else '' end) KRK_SBP,
    max(case when KRKPPGFilePath is not null then DBP else '' end) KRK_DBP,
    max(case when PPGFilePath is not null then PPGFilePath else '' end) PPGFilePath1 , 
    max(case when PPGFilePath is not null then SBP else '' end) YD_SBP,
    max(case when PPGFilePath is not null then DBP else '' end) YD_DBP,
    max(case when PPGFilePath is not null then Ecgdisease else '' end) Ecgdisease,
    max(case when PPGFilePath is not null then EcgHRV else '' end) EcgHRV
    from (
    select     p.PatientID ,p.PPGFilePath, p.KRKPPGFilePath, p.SBP, p.DBP, pa.Age, pa.Sex, pa.Height, pa.Weight,pa.BMI,p.OperatorID,p.Ecgdisease,p.EcgHRV
    FROM
        ppg_data AS p
        LEFT JOIN 
        (select *,pa.Weight/power(pa.Height,2)*10000 as BMI from patient AS pa)pa ON p.PatientID=pa.PatientID 
        LEFT JOIN operator AS o ON o.OperatorID = p.OperatorID
        where   p.PatientID not  IN (SELECT PatientID from patient_fortest)
        and p.PatientID in (
        select A.PatientID from (    select * from (select * from
         (SELECT
        p.DataID,p.Quality,p.PatientID , p.PPGFilePath, p.SBP, p.DBP, pa.Age, pa.Sex, pa.Height, pa.Weight,round( pa.BMI,2)BMI,p.ECGFilePath, p.OperatorID
    FROM
        ppg_data AS p
        LEFT JOIN 
        (select *,pa.Weight/power(pa.Height,2)*10000 as BMI from patient AS pa)pa ON p.PatientID=pa.PatientID
        LEFT JOIN operator AS o ON o.OperatorID = p.OperatorID
    WHERE
        p.TestEndTime >= '2019-12-17 00:00:01' 
        AND p.TestEndTime < '2020-07-08 00:00:01' 
        AND p.State = '1' 
        AND p.Quality='1'
        AND pa.Age>=16
        AND pa.Age<=120
        AND pa.Weight>=30
        AND pa.Weight<=160
        AND pa.Height>=130
        AND pa.Height<=220
        AND p.SBP>p.DBP
        AND BMI>=15
        AND BMI<=50
        AND pa.RecordIsDeleted = 0
        AND o.isCensus = 1
        AND p.KRKPPGFilePath IS NOT NULL 
        AND p.SBP IS NOT NULL
    ORDER BY p.PatientID)as p order by p.Quality desc,DataID desc
    limit 30000)p
    group by p.PatientID )A
        join 
        (select * from (select * from
         (SELECT
        p.DataID,p.Quality,p.PatientID , p.PPGFilePath, p.SBP, p.DBP, pa.Age, pa.Sex, pa.Height, pa.Weight,round( pa.BMI,2)BMI,p.ECGFilePath, p.OperatorID
    FROM
        ppg_data AS p
        LEFT JOIN 
        (select *,pa.Weight/power(pa.Height,2)*10000 as BMI from patient AS pa)pa ON p.PatientID=pa.PatientID
        LEFT JOIN operator AS o ON o.OperatorID = p.OperatorID
    WHERE
        p.TestEndTime >= '2019-12-17 00:00:01' 
        AND p.TestEndTime < '2020-07-08 00:00:01' 
        AND p.State = '1' 
        AND p.Quality='1'
        AND pa.Age>=16
        AND pa.Age<=120
        AND pa.Weight>=30
        AND pa.Weight<=160
        AND pa.Height>=130
        AND pa.Height<=220
        AND p.SBP>p.DBP
        AND BMI>=15
        AND BMI<=50
        AND pa.RecordIsDeleted = 0
        AND o.isCensus = 1
        AND p.PPGFilePath IS NOT NULL 
        AND p.SBP IS NOT NULL
    ORDER BY p.PatientID)as p order by p.Quality desc,DataID desc
    limit 30000)p
    group by p.PatientID  )B
        on A.PatientID=B.PatientID )
        and p.TestEndTime >= '2019-12-17 00:00:01' 
        AND p.TestEndTime < '2020-07-08 00:00:01' 
        AND p.State = '1' 
      and p.Quality=1
        AND pa.Age>=16
        AND pa.Age<=120
        AND pa.Weight>=30
        AND pa.Weight<=160
        AND pa.Height>=130
        AND pa.Height<=220
        AND p.SBP>p.DBP
        AND BMI>=15
        AND BMI<=50
        AND pa.RecordIsDeleted = 0
        AND o.isCensus = 1
        AND p.SBP IS NOT NULL
    ORDER BY p.PatientID)A
    group by  PatientID ,  Age, Sex, Height, Weight,BMI
  • 相关阅读:
    Leetcode-2 两数相加
    离散数学-基本割集的找法
    Linux操作系统分析课程学习总结报告
    Linux实验三 结合中断上下文切换和进程上下文切换分析Linux内核一般执行过程
    Linux实验二:深入理解系统调用
    初始python
    水仙花数讲解
    Python-运算
    Python-列表
    Python-字符串
  • 原文地址:https://www.cnblogs.com/zhanghongpan/p/13275447.html
Copyright © 2011-2022 走看看