久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQL將兼容性矩陣轉化為映射表(列轉化為行)

SQL convert compatibility matrix into mapping table (columns into rows)(SQL將兼容性矩陣轉化為映射表(列轉化為行))
本文介紹了SQL將兼容性矩陣轉化為映射表(列轉化為行)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有下表:

我想將矩陣轉換成這種格式:

I want to convert the matrix to this format:

其中新的映射表代表一組選項和使用這些選項的一組模型之間的兼容性,數值代表該特定模型的選項的價格.

where the new mapping table represents the compatibility between a set of options and a set of models that use those options, and the numeric values represent the price of an option for that specific model.

請記住,這只是來自更大表的一個小樣本,因此查詢需要或多或少是動態的,而不是基于此示例中提供的選項或模型的數量進行硬編碼.

Bare in mind that this is just a small sample from a much bigger table, so the query needs to be more or less dynamic and not hardcoded based on the number of options or models provided in this example.

有誰知道我如何實現這一目標?

Does anyone know how I can achieve this?

最好的問候,

推薦答案

UnPivot 或 Gordon 的答案會更高效,但這里有一個選項可以動態"取消數據或查詢,而無需實際使用動態 SQL.

UnPivot or Gordon's answer would be more performant, but here is an option that will "dynamically" unpivot your data or query without actually using dynamic SQL.

示例

Select A.OptionID
      ,ModelName  = C.Item
      ,Price      = C.Value
 From  YourTable A
 Cross Apply ( values (cast((Select A.* for XML RAW) as xml))) B(XMLData)
 Cross Apply (
                Select Item  = a.value('local-name(.)','varchar(100)')
                      ,Value = a.value('.','varchar(max)') --<< Change to desired datatype
                 From  B.XMLData.nodes('/row')  as C1(n)
                 Cross Apply C1.n.nodes('./@*') as C2(a)
                 Where a.value('local-name(.)','varchar(100)') not in ('OptionID','OtherFieldsToExclude')
             ) C

退貨

這篇關于SQL將兼容性矩陣轉化為映射表(列轉化為行)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 精品成人一区 | 91在线一区 | 亚洲一区二区三区 | 日韩成人av在线 | 亚洲一区二区日韩 | 精品国产免费人成在线观看 | 欧美综合一区二区三区 | 午夜免费视频 | 毛片一区| 国产在线精品免费 | 中文字幕av在线一二三区 | 大吊一区二区 | 9porny九色视频自拍 | 99九色| 午夜不卡一区二区 | 91国内外精品自在线播放 | 五月激情婷婷在线 | 午夜免费av | 精品国产乱码久久久久久影片 | 国产精品99久久久久久动医院 | 成人在线中文字幕 | 免费观看一级特黄欧美大片 | 国产成人av在线播放 | 97国产精品视频人人做人人爱 | 免费午夜剧场 | 久久精品成人 | 亚洲精品二区 | 日韩毛片在线视频 | 中文在线视频 | 天天视频一区二区三区 | 四虎影院在线观看免费视频 | 午夜欧美 | 国产日韩久久久久69影院 | 一区二区三区免费在线观看 | 久久小视频 | 亚洲国产aⅴ精品一区二区 免费观看av | 在线中文视频 | 国产成人午夜电影网 | 国产高清视频一区 | 欧美精品一区二区免费 | 精品欧美乱码久久久久久1区2区 |