ต้องการดูข้อมูล eGFR 3 ครั้งล่าสุดครับ แนะนำทีครับ
select v1.vn as vn1,
( # eGFR1
if(pt1.sex=1 and s1.creatinine<=0.9,141*exp(-0.411*ln(s1.creatinine/0.9))*exp(v1.age_y*ln(0.993)),
if(pt1.sex=1 and s1.creatinine>=0.9,141*exp(-1.209*ln(s1.creatinine/0.9))*exp(v1.age_y*ln(0.993)),
if(pt1.sex=2 and s1.creatinine<=0.7,144*exp(-0.329*ln(s1.creatinine/0.7))*exp(v1.age_y*ln(0.993)),
if(pt1.sex=2 and s1.creatinine>=0.7,144*exp(-1.209*ln(s1.creatinine/0.7))*exp(v1.age_y*ln(0.993)),"0"))))
) as eGFR1,v1.vstdate as vstdate1,
v2.vn as vn2,
( # eGFR2
if(pt2.sex=1 and s2.creatinine<=0.9,141*exp(-0.411*ln(s2.creatinine/0.9))*exp(v2.age_y*ln(0.993)),
if(pt2.sex=1 and s2.creatinine>=0.9,141*exp(-1.209*ln(s2.creatinine/0.9))*exp(v2.age_y*ln(0.993)),
if(pt2.sex=2 and s2.creatinine<=0.7,144*exp(-0.329*ln(s2.creatinine/0.7))*exp(v2.age_y*ln(0.993)),
if(pt2.sex=2 and s2.creatinine>=0.7,144*exp(-1.209*ln(s2.creatinine/0.7))*exp(v2.age_y*ln(0.993)),"0"))))
) as eGFR2,v2.vstdate as vstdate2,
v3.vn as vn3,
( # eGFR3
if(pt3.sex=1 and s3.creatinine<=0.9,141*exp(-0.411*ln(s3.creatinine/0.9))*exp(v3.age_y*ln(0.993)),
if(pt3.sex=1 and s3.creatinine>=0.9,141*exp(-1.209*ln(s3.creatinine/0.9))*exp(v3.age_y*ln(0.993)),
if(pt3.sex=2 and s3.creatinine<=0.7,144*exp(-0.329*ln(s3.creatinine/0.7))*exp(v3.age_y*ln(0.993)),
if(pt3.sex=2 and s3.creatinine>=0.7,144*exp(-1.209*ln(s3.creatinine/0.7))*exp(v3.age_y*ln(0.993)),"0"))))
) as eGFR3,v3.vstdate as vstdate3
from vn_stat v1
inner join vn_stat v2 on v2.vn = v1.vn
inner join vn_stat v3 on v3.vn = v2.vn
inner join opdscreen s1 on s1.vn = v1.vn
inner join opdscreen s2 on s2.vn = v2.vn
inner join opdscreen s3 on s3.vn = v3.vn
inner join patient pt1 on pt1.hn = v1.hn
inner join patient pt2 on pt2.hn = v2.hn
inner join patient pt3 on pt3.hn = v3.hn
where
(
v1.main_pdx between 'N181' and 'N189' and
v2.main_pdx between 'N181' and 'N189' and
v3.main_pdx between 'N181' and 'N189'
)