ลองใช้ค่า r.w. มาช่วยคำนวนดูครับ
select a.pdx,i.name as pdx_name,sum(a.income*ipt.rw) as sum_rwincome ,sum(a.income) as sum_income
from an_stat a
left outer join ipt ipt on ipt.an = a.an
left outer join icd101 i on i.code = a.pdx
where a.dchdate between "2007-01-01" and "2007-01-31"
group by a.pdx,i.name
order by sum_rwincome desc limit 10