query CT Scan, x-ray ตึก สธ.

query CT

SET @startdate = '2024-10-01';
SET @enddate = '2025-09-30';
 
select
COUNT(DISTINCT a.an) as 'visit'
from ipt a
INNER JOIN opitemrece b ON a.an = b.an
INNER JOIN xray_items c ON b.icode = c.icode
INNER JOIN xray_items_group d ON c.xray_items_group = d.xray_items_group
WHERE a.regdate BETWEEN @startdate AND @enddate
AND d.`name` = 'CT'
AND a.ward IN ('10','11')

query X-Ray

SET @startdate = '2024-10-01';
SET @enddate = '2025-09-30';
 
select
COUNT(DISTINCT a.an) as 'visit'
from ipt a
INNER JOIN opitemrece b ON a.an = b.an
INNER JOIN xray_items c ON b.icode = c.icode
INNER JOIN xray_items_group d ON c.xray_items_group = d.xray_items_group
WHERE a.regdate BETWEEN @startdate AND @enddate
AND d.`name` = 'X-Ray'
AND a.ward IN ('10','11')