BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: nan_it ที่ มกราคม 16, 2007, 20:50:00 PM

หัวข้อ: คำสั่งสุ่มหา HN
เริ่มหัวข้อโดย: nan_it ที่ มกราคม 16, 2007, 20:50:00 PM
อ.ครับ คำสั่งสุ่มหา HN ตามเงือนไขที่เรากำหนด เช่น ต้องการหาข้อมูลคนไข้ที่มี HN ลงท้ายด้วยเลข 9 ใช้คำสั่งอะไรครับ ขอบคุณครับ
หัวข้อ: Re: คำสั่งสุ่มหา HN
เริ่มหัวข้อโดย: nayok ที่ มกราคม 16, 2007, 21:07:40 PM
ขออนุญาตตอบแทนอ.นะครับ
select field from table
where hn like"%9"  ครับ
หัวข้อ: Re: คำสั่งสุ่มหา HN
เริ่มหัวข้อโดย: gu_prajag ที่ มีนาคม 12, 2007, 22:38:59 PM
จากคำสั่ง select field from table where hn like"%9"
เป็นการเลือกข้อมูลที่ลงท้ายด้วยเลข 9 อะแต่ไม่ใช่การสุ่ม
ขออนุญาติเพิ่มเติม ครับ
ผมทดสอบกับตาราง pateint สุ่มผู้ป่วยที่มี hn ลงท้ายด้วยเลข 9 อะ
SELECT *
FROM patient
where hn like '%9'
group by rand() limit 10
คำสั่ง limit 10 หมายถึงสุ่มมา 10 คนอะ
หรือใครประยุกต์ใช้คำสั่ง  right ตัดให้เหลือเลข 9 ตัวเดียวก็ได้ตรง where right(hn,1)='9'
SELECT *
FROM patient
where right(hn,1)='9'
group by rand() limit 10

หัวข้อ: Re: คำสั่งสุ่มหา HN
เริ่มหัวข้อโดย: kchosp ที่ มีนาคม 13, 2007, 01:32:29 AM
ขออนุญาตถามน่าจะเรื่องเดียวกันนะครับ คือ ผมต้องการหา 20 อันดับโรคผู้ป่วยใน ของชาวต่างด้าว โดยอาจจะระบุว่า nationality <>99 น่าจะเพิ่มคำสั่งอย่างไรครับ

select v.pdx,count(v.pdx) as pdx_count, i.name as icdname
from an_stat v
left outer join icd101 i on i.code=v.pdx
where v.dchdate between "2003-01-01" and "2003-01-31" and v.pdx is not null and v.pdx<>""
group by v.pdx,i.name
order by pdx_count desc
limit 20
หัวข้อ: Re: คำสั่งสุ่มหา HN
เริ่มหัวข้อโดย: gu_prajag ที่ มีนาคม 13, 2007, 21:08:06 PM
select v.pdx,count(v.pdx) as pdx_count, i.name as icdname
from an_stat v
left outer join icd101 i on i.code=v.pdx
left outer join pttype p on p.pttype=v.pttype
where v.pttype="62" and (v.dchdate between "2003-01-01" and "2003-05-31") and v.pdx is not null and v.pdx<>""
group by v.pdx,i.name
order by pdx_count desc
limit 20
//pttype="62" สิทธิคนต่างด้าว อะ