SQL Row data to Column with another column name

徘徊边缘 提交于 2019-12-08 13:42:34

问题


My data as follow:

> mydata

   month count1 count2 count3
1 201301    100    110     50
2 201302    150    160     60
3 201303    200    210     50

My expected data like this:

>final data

count_all  201301 201302 201303
1 count1       100    150    200
2 count2       110    160    210
3 count3        50     60     50

How can I get the result using SQL? I know PIVOT a little, but it seems there are some problems in the column name during my processing. I need an efficient way to resolve this problem. And I will execute such a query:select * from final_data where count_all='count1'.So if not with thisrow-column transformation,I don't know how to get a similar result.

来源:https://stackoverflow.com/questions/21845564/sql-row-data-to-column-with-another-column-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!