本文介紹了使用 SQL 轉(zhuǎn)置表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我有一個這樣的 SQL 表
<前>光伏區(qū)CouterParty851 M010名稱1561 M011名稱2869 M012名稱3...而且我需要使用 T-SQL(不是報告服務(wù)或其他任何東西)轉(zhuǎn)貼它,使其看起來像這樣:
<前>對方 M010 M011 M012 ....姓名 1 851名稱2 561姓名2 869問題是我不知道我將有多少個區(qū)號,所以實(shí)際上可能有任意數(shù)量的列.
任何想法我怎么能做到這一點(diǎn)?感謝一百萬
解決方案
你將不得不做一個動態(tài)交叉表,查看這些文章:
- SQLServer:動態(tài)交叉-標(biāo)簽
- 動態(tài)交叉表/數(shù)據(jù)透視表立>
- Crosstab 數(shù)據(jù)透視表工作臺
- SQL 動態(tài)交叉表存儲過程
I have a SQL table like so
PV Area CouterParty 851 M010 Name1 561 M011 Name2 869 M012 Name3 ...
And I need to transpost it, using T-SQL (not reporting services or anything else), so that it looks like this:
CounterParty M010 M011 M012 .... Name1 851 Name2 561 Name2 869
The thing is that I do not know how many Area codes I will have, so there could be any number of columns really.
Any ideas how I can do this? Thanks a milion
解決方案
You will have to do a Dynamic CrossTab, check these articles:
- SQLServer: Dynamic Cross-Tab
- Dynamic Cross-Tabs/Pivot Tables
- Crosstab Pivot-table Workbench
- SQL Dynamic CrossTab Stored Procedure
這篇關(guān)于使用 SQL 轉(zhuǎn)置表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!