SQL : query ยอดรวมจำนวนค่าซ่อมของแต่ละเดือน ได้ใน SQL คำสั่งเดียว ไม่ต้อง where ทีละเดือน

joy / 28 February, 2009

วิธีเขียน sql query หายอดรวมจำนวนค่าซ่อมของรถทุกคัน แยกเป็นแต่ละเดือน   ได้ใน SQL คำสั่งเดียว ไม่ต้อง where ทีละเดือน  select license_no, sum(case when month(bill_date)=1 then bill_amt else 0 end) as [Jan], sum(case when month(bill_date)=2 then bill_amt else 0 end) as [Feb], sum(case when month(bill_date)=3 then bill_amt else 0 end) as [Mar], sum(case when month(bill_date)=4 then bill_amt else 0 end) as [Apr], sum(case...