BMS-HOSxP Community
HOSxP => Report Exchange => ข้อความที่เริ่มโดย: stealth ที่ ตุลาคม 10, 2012, 15:10:55 PM
-
ช่วยดูคำสั่งตามนี้หน่อยคับ คือ ที่ต้องการ
select vn,hn,an,pttype,income ,sum(sum_price)as xray
from opitemrece
where pttype in (89) and hn ='000279709'
and vstdate between '2012-08-30' and '2012-09-04'
and an <> '0'
and income in (08)
อยากให้คำนวณค่า ผลรวม sum_price แยกออกมาตามแต่ละ income ต้องเพิ่มเติมคำสั่ง Mysqlด้านบนอย่างไร บ้างคับ
hn.. an.. pttype.. xray lab ค่าห้อง ค่ายา
1111 2222 89 80 90 100 200
2222 3333 89 10 20 100 50
-
ลอง
select vn,hn,an,pttype,income ,
SUM(IF(income="07",sum_price,0)) as xray,
SUM(IF(income="08",sum_price,0)) as lab,
SUM(IF(income="09",sum_price,0)) as ค่าห้อง,
SUM(IF(income="10",sum_price,0)) as ค่ายา,
from opitemrece
where pttype in (89) and hn ='000279709'
and vstdate between '2012-08-30' and '2012-09-04'
and an <> '0'