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
  • 相关阅读:
    UITabBarController生命周期(使用storyoard搭建)
    ios应用数据存储方式(归档)
    ios应用数据存储方式(偏好设置)
    使用picker View控件完成一个简单的选餐应用
    ios应用数据存储方式(XML属性列表-plist)
    控制器的View的创建
    控制器的创建
    权限管理具体代码实现
    gitHub相关
    初始Ajax
  • 原文地址:https://www.cnblogs.com/zhanghongpan/p/13275447.html
Copyright © 2011-2022 走看看