BMS-HOSxP Community
HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Bluebird ที่ สิงหาคม 03, 2009, 09:20:29 AM
-
select count(ov.hn) as chn
from vn_stat ov, ovst ovst, patient pt
where ov.vn=ovst.vn and pt.hn=ov.hn and ov.vstdate between "2009-07-01" and "2009-07-31"
and ov.age_y>= 40
จากคำสั่งดังกล่าวได้ยอดทั้งหมด แต่ต้องการแยกเป็นตำบลด้วยครับต้องเพิ่มคำสั่งหรือเปลี่ยนแปลงตรงไหนบ้างครับ
-
select v.aid,t.full_name,count(v.vn) as cc
from vn_stat v
left join thaiaddress t on t.addressid=v.aid
where v.vstdate between "2009-07-01" and "2009-07-31"
and v.age_y>40
group by v.aid
-
หากอยากได้ทั้งจำนวนคนด้วยล่ะครับ เพราะนี้แค่จำนวนครั้งเองไม่ใช่หรอ
-
select a.aid,ifnull(t.full_name,if(left(a.aid,2)='62','ในจังหวัด','จังหวัดอื่น')) as name
,count(distinct a.hn) as 'case',count(a.hn) as 'total'
from (select v.vn,v.hn
,if(left(v.aid,4)='6210',v.aid
,if(left(v.aid,2)='62','629999','999999')) as aid
from vn_stat v
where v.vstdate between "2009-07-01" and "2009-07-31"
and v.age_y>=40 ) a
left join thaiaddress t on a.aid=t.addressid
group by a.aid
order by a.aid
ลองแก้เป้นรหัสจังหวัด อำเภอของเรา
ลองดูคับ
-
(ได้แค่นี้ก็โอเคแล้ว พอไปส่ง ต้องการเพิ่มอีก ทำไมไม่บอกให้หมดแต่แรกน่ะ จะได้ทำครั้งเดียว) คำบ่นจากเจ้าหน้าที่ IT :-\ :-\
ต้องการทราบว่า ใหม่ในเดือนกี่คนด้วยจากแบบฟอร์มเดิม
-
:D
-
select a.aid,ifnull(t.full_name,if(left(a.aid,2)='62','ในจังหวัด','จังหวัดอื่น')) as name
,count(distinct a.hn) as 'case',count(a.hn) as 'total'
,sum(count_in_month=0) as new_month
,sum(count_in_year=0) as new_year
from (select v.vn,v.hn,count_in_year,count_in_month
,if(left(v.aid,4)='6210',v.aid
,if(left(v.aid,2)='62','629999','999999')) as aid
from vn_stat v
where v.vstdate between "2009-07-01" and "2009-07-31"
and v.age_y>=40 ) a
left join thaiaddress t on a.aid=t.addressid
group by a.aid
order by a.aid