mysql - Same month two different SUMS -


i'm trying different sums same month on same year, sums different types. tried using code:

select a.invoice_type, year( a.date ) year,         date_format( a.date, '%m' ) `month` ,         sum( x.amount * x.price ) sum records x  join paper_invoice on x.invoice_id = a.invoice_id  year( a.date ) = '2012'  group a.invoice_type, year( a.date ) , month( a.date ) limit 0 , 30      

but gives results in different rows:

http://www.part.lt/img/1505f0f13172922150febede85ddbf0925.png

but need like:

year | month   | sum_grynais      | sum_pavedimu 2012 | january | 7597.14997705445 | 58740.2800849304 

and etc.

try this:

select year, month, max(case when invoice_type = 'grynais' sum end) sum_grynais max(case when invoice_type = 'pavedimu' sum end) sum_pavedimu ( select a.invoice_type, year( a.date ) year,  date_format( a.date, '%m' ) `month` , sum( x.amount * x.price ) sum  records x join paper_invoice on x.invoice_id = a.invoice_id  year( a.date ) = '2012' group a.invoice_type, year( a.date ) ,  month( a.date ) limit 0 , 30       ) group year, month 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -