MySQL Select Query to generate dynamic column Result

前端 未结 2 534

I need to write a query that returns a Column Dynamically. For example I have a table tblTest with columns:

Id, Name,   Type,  Amount
1, Receipt, Cash   100
         


        
2条回答
  •  梦谈多话
    2021-01-14 08:23

    Hej,

    Hope i got you right.

    select name, type, sum(CASE WHEN Type in (select DISTINCT sub.type from 
    tblTest sub) THEN Amount ELSE 0 END) as "sum" from tblTest
    group by name, type;
    

提交回复
热议问题