SQL show grouping on the same row

The table structure of the database is like this



 

Then you need to get the query result like this




 

The sql statement is like this

 

select name,

'b1' as b1,   sum(case when bag = 'b1' then money end),

'b2' as b2,   sum(case when bag = 'b2' then money end),

'sum' as summ,sum(money)

from testtable

group by name;

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327070567&siteId=291194637