BMS-HOSxP Community
HOSxP => MySQL => ข้อความที่เริ่มโดย: mr.yung ที่ พฤษภาคม 31, 2012, 12:08:50 PM
-
มีคำถามเกี่ยวกับการใช้คำสั่ง mysql ครับ
คือว่าจากคำสั่ง sql ด้านล่างนี้ ผมต้องการหา hn ที่มีการให้ diag โรคคือ Z392 และ Z014 ซึ่งมันก็ได้ผลและแสดงออกมา แต่ทีนี้ถ้าผมต้องการจะให้แสดงจำนวนของ hn ที่หาได้หละครับ ผมหมายถึงการ count hn ที่หาได้อีกทีนึง เราต้องปรับการเขียน sql อย่างไร ดังภาพด้านล่าง ซึ่งได้มา 5 เรคคอร์ด
select hn, count(hn) as cou from ovstdiag
where icd10 in("Z392", "Z014")
and vstdate between "2012-04-01" and "2012-04-30"
group by hn
having cou>1
-
ใช้ count(distinct hn) ครับ
-
ใช่นับ hn ที่หาได้หรือมัย
SELECT count(A.hn)
from (select hn, count(hn) as cou from ovstdiag
where icd10 in("Z392", "Z014")
and vstdate between "2012-04-01" and "2012-04-30"
group by hn
having cou>1) A
-
มีคำถามเกี่ยวกับการใช้คำสั่ง mysql ครับ
คือว่าจากคำสั่ง sql ด้านล่างนี้ ผมต้องการหา hn ที่มีการให้ diag โรคคือ Z392 และ Z014 ซึ่งมันก็ได้ผลและแสดงออกมา แต่ทีนี้ถ้าผมต้องการจะให้แสดงจำนวนของ hn ที่หาได้หละครับ ผมหมายถึงการ count hn ที่หาได้อีกทีนึง เราต้องปรับการเขียน sql อย่างไร ดังภาพด้านล่าง ซึ่งได้มา 5 เรคคอร์ด
select hn, count(hn) as cou,count(distinct hn) as aou from ovstdiag
where icd10 in("Z392", "Z014")
and vstdate between "2012-04-01" and "2012-04-30"
group by hn
having cou>1
-
มีคำถามเกี่ยวกับการใช้คำสั่ง mysql ครับ
คือว่าจากคำสั่ง sql ด้านล่างนี้ ผมต้องการหา hn ที่มีการให้ diag โรคคือ Z392 และ Z014 ซึ่งมันก็ได้ผลและแสดงออกมา แต่ทีนี้ถ้าผมต้องการจะให้แสดงจำนวนของ hn ที่หาได้หละครับ ผมหมายถึงการ count hn ที่หาได้อีกทีนึง เราต้องปรับการเขียน sql อย่างไร ดังภาพด้านล่าง ซึ่งได้มา 5 เรคคอร์ด
select hn, count(hn) as cou from ovstdiag
where icd10 in("Z392", "Z014")
and vstdate between "2012-04-01" and "2012-04-30"
group by hn
having cou>1
ลองแบบนี้ดูค่ะ ;) ;)
select count(distinct(o.hn)) as amount_hn
from ovstdiag o,(select hn, count(hn) as cou from ovstdiag
where icd10 in("Z392", "Z014") and vstdate between "2012-04-01" and "2012-04-30"
group by hn having cou>1 ) as temp
where o.hn=temp.hn
-
ใช่นับ hn ที่หาได้หรือมัย
SELECT count(A.hn)
from (select hn, count(hn) as cou from ovstdiag
where icd10 in("Z392", "Z014")
and vstdate between "2012-04-01" and "2012-04-30"
group by hn
having cou>1) A
ขอบคุณมากครับ นี่แหละ ใช่เลย