我想在同一年得到與當月不同的總和,只是爲了得到不同類型的總和。使用此代碼嘗試:同一月份兩個不同的SUMS
SELECT a.invoice_type, year(a.date) AS Year,
date_format(a.date, '%M') AS `month` ,
Sum(x.amount * x.price) AS sum FROM records x
JOIN paper_invoice a ON x.invoice_id = a.invoice_id
WHERE year(a.date) = '2012'
GROUP BY a.invoice_type, Year(a.date) , Month(a.date) LIMIT 0 , 30
,但它給出了不同行的結果:
http://www.part.lt/img/1505f0f13172922150febede85ddbf0925.png
但我需要它看起來像:
Year | Month | SUM_GRYNAIS | SUM_PAVEDIMU
2012 | January | 7597.14997705445 | 58740.2800849304
等。
感謝這一個工作。完善! :) –