sql - Group by 2 field in mysql -


this question has answer here:

how group data 2 column result in 1 row (like when join it).

this table 'jembatan'

id    nama   tahun    jumlah ----------------------------- 1          2011     12 2     b      2011     10 3          2011     23 4     b      2012     11 

i want result this:

id    totala     totalb     tahun ---------------------------------       25         10         2011       0          11         2012 

how that?

you want conditional aggregation:

select sum(case when nama = 'a' jumlah else 0 end) totala,        sum(case when nama = 'b' jumlah else 0 end) totalb,        tahun t group tahun; 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -