BMS-HOSxP Community
HOSxP => Report Exchange => ข้อความที่เริ่มโดย: naydekdee ที่ สิงหาคม 17, 2011, 12:15:17 PM
-
รายงานความดันเบาหวานแทรกซ้อน จำแนกอายุ แต่ว่า ด้วยความถนัดผมจะเขียนผ่าน variable ซึ่งรายงานตัวนี้เยอะ มาก เลยคับ หากว่า เขียนผ่าน variable จะมีประมาณ 363 variable จึงขอคตำแนะนำวิธีการเขียนที่ไม่ต้องอาศัย variable น่ะคับ พอมีวิธีไหมคับ ใครมี ช่วยแนะนำหน่อยอ่ะคับ
ผมหาในบอร์ดแล้ว แต่ว่าส่วนใหญ่จะเขียนผ่าน variable จึงอยากรู้ วิธีการเขียนแนวอื่นๆ บ้าง เผื่อจะประหยัดเวลาในการ query ข้อมูล ได้บ้าง คับ
ขอบคุณนะคับ
ปล แนบตัวอย่างแบบรายงานให้น่ะคับ
-
ปรึกษา..เจมส์..นครศรีธรรมราชครับ... :D ;D ;D
-
ประมาณนี้มั๊ย
set @mclinic:=001;
select m.*,a.*
from (select 0 as 'cormobidity','ไม่มีภาวะแทรกซ้อน' as 'name'
union select cormobidity,name from clinic_cormobidity where clinic=@mclinic) m
left join (select cormobidity
,sum(if(sex='1' and age<40,1,0)) 'Male_less_40'
,sum(if(sex='1' and age between 40 and 49,1,0)) 'Male_40'
,sum(if(sex='1' and age between 50 and 60,1,0)) 'Male_50'
,sum(if(sex='1' and age>=60,1,0)) 'Male_more_60'
,sum(if(sex='2' and age<40,1,0)) 'FeMale_less_40'
,sum(if(sex='2' and age between 40 and 49,1,0)) 'FeMale_40'
,sum(if(sex='2' and age between 50 and 60,1,0)) 'FeMale_50'
,sum(if(sex='2' and age>=60,1,0)) 'FeMale_more_60'
from (select c.hn,ifnull(cc.cormobidity,0) cormobidity
,p.sex,timestampdiff(year,p.birthday,now()) age
from clinicmember c
left join patient p on p.hn=c.hn
left join clinic_cormobidity_list cc on c.hn=cc.hn and cc.clinic=@mclinic
where c.clinic=@mclinic
order by c.hn,cormobidity) a
group by cormobidity) a on a.cormobidity=m.cormobidity
*****
แต่น่าจะไปผิดตรงผลรวม
เพราะบางครั้งมีภาวะแทรกซ้อนมากกว่า 1 อย่าง
เช่น DM แล้วแทรกซ้อน ตา กับ ไต นับกันอย่างไร
ต้องหาวิธีการนับกันก่อน
-
ปรึกษา..เจมส์..นครศรีธรรมราชครับ... :D ;D ;D
ถูกต้องแล้ว หาเจอได้ที่ Hosxp ON FACEBOOK นะคะ