transpose rows to columns in sql

前端 未结 3 1330
广开言路
广开言路 2021-01-23 10:32

I have problem in getting the desired output with the SQL query.

My sql data is as follows:

TOTAL   Charge      PAYMNET      A         B        C                 


        
3条回答
  •  不思量自难忘°
    2021-01-23 11:09

    Select Month(Mdate)md,'A' AS Col,sum(A) as a from Product group by Month(MDate)
    union all
    Select Month(Mdate)md,'B',sum(b) as a from Product group by Month(MDate)
    union all
    Select Month(Mdate)md,'C',sum(c) as a from Product group by Month(MDate)
    union all
    Select Month(Mdate)md,'D',Count(A) as a from Product group by Month(MDate)
    

    Try Pivot with the above query you may to get required result....

提交回复
热议问题