Monday, February 4, 2013

คำสั่ง Query ที่ใช้ดึงกลุ่มเป้าหมายคัดกรอง 2Q /พี่บอย


สวัสดีเช้าวันจันทร์ เดือนแห่งความรัก "กุมภาพันธ์" 2556
วันนี้ประเดิมด้วยคำสั่ง SQL ตามนี้


SELECT CONCAT(p.pname,p.fname,"  ",p.lname) as ptname,p.cid,p.informaddr,p.tmbpart,d.hn,d.icd10,i.`name`,d.vstdate from ovstdiag d
LEFT OUTER JOIN patient p on p.hn=d.hn
LEFT OUTER JOIN icd101 i on i.`code`=d.icd10
WHERE vstdate BETWEEN "2012-10-01" and "2013-01-31" 
and (icd10 like ("E11%") or icd10 LIKE ("i10%") or  icd10   BETWEEN "N180" and "N189" or icd10   BETWEEN "I60" and "I69" or 
icd10 in ("I05","I050","I051","I052","I058","I059","I06","I060","I061","I062","I068","I069","I07","I070","I071","I072","I078","I079","I08","I080","I081","I082","I083", 
              '"I088","I089","I09","I090","I091","I092","I098","I099","I20","I200","I201","I208","I209","I21","I210","I211","I212","I213","I214","I219","I22","I220","I221","I228",            
              '"I229","I23","I230","I231","I232","I233","I234","I235","I236","I238","I24","I240","I241","I248","I249","I25","I250","I251","I252","I253","I254","I255","I256",                    
              '"I258","I259","I30","I300","I301","I308","I309","I31","I310","I311","I312","I313","I318","I319","I32","I320","I321","I328","I33","I330","I339","I34","I340","I341",                
              '"I342","I348","I349","I35","I350","I351","I352","I358","I359","I36","I360","I361","I362","I368","I369","I37","I370","I371","I372","I378","I379","I38","I39","I390",                  
              '"I391","I392","I393","I394","I398","I40","I400","I401","I408","I409","I41","I410","I411","I412","I418","I42","I420","I421","I422","I423","I424","I425","I426","I427",                  
              '"I428","I429","I43","I430","I431","I432","I438","I44","I440","I441","I442","I443","I444","I445","I446","I447","I45","I450","I451","I452","I453","I454","I455","I456",                    
              '"I458","I459","I46","I460","I461","I469","I47","I470","I471","I472","I479","I48","I49","I490","I4900","I4901","I4908","I4909","I491","I492","I493","I494","I495",                          
              '"I498","I499","I50","I500","I501","I509","I51","I510","I511","I512","I513","I514","I515","I516","I517","I518","I519","I52")  )
GROUP BY d.hn
ORDER BY d.icd10

โดยมีเงื่อนไข
1. ช่วงวันที่ vstdate BETWEEN "2012-10-01" and "2013-01-31" 
2. icd10 ตามเงื้นไขที่กำหนด เยอะไปหน่อย
3. GROUP By d.hn  รวม hn ที่ซ้ำกัน
4. ORDER By icd10 ให้เรียงลำดับตามรหัส icd10

ตารางที่เกี่ยวข้อง
1. ovstdiag  เก็บรหัสวินิจฉัยการพยาบาลทั้งหมด
2. patient เก็บข้อมูลผู้รับบริการ
3. icd101 เก็บรายละเอียดของรหัส ICD10 TM


จบบทความ  เอาไปคัดกรองภาวะซึมเศร้าในเดือนแห่งความรัก T____T นะครับ
#keepper

0 ความคิดเห็น:

Post a Comment

 

Sample Text

111

Sample Text