วันจันทร์ที่ 15 มิถุนายน พ.ศ. 2558

การเขียน subquery mysql example

Here is an example of a subquery
มาดูการหาข้อมูลตามเงื่อนไข อันนี้นี้เป็นการหาจริง จากการขอข้อมูลจริง วันนี้สดๆ ร้อนๆ โดยการสร้างรายงานซ้อนรายงาน หรือรายงานย่อยของรายงานหลัก



ตัวอย่างการใช้งานของ Subquery mysql example
SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);

ตัวอย่างที่ผมใช้
SELECT *,c.hn,vstdate,egfr,age_y 
,(SELECT pe.age_y from clinicmember c
LEFT OUTER JOIN person pe on pe.patient_hn = c.hn
WHERE c.hn = o.hn limit 1) as age_y99
FROM clinicmember c
LEFT OUTER JOIN opdscreen o on o.hn = c.hn 
WHERE o.vstdate BETWEEN "2014-10-01" and "2015-05-31" 
and egfr is not null ;