如果我運行,我會從我的表中select columnA from tableA獲取值。columnA
如果我運行,select columnB, columnC from tableA as xml path, root我會從格式化為 XML 的 2 列中獲取資料。
如何將上述 2 個查詢的效果合并為一個,以便在單獨的列中按原樣回傳columnA并columnB使用XML 標記?columnCmyXml
我在 SQL2008R2 服務器上運行它。
uj5u.com熱心網友回復:
with myTable as (
select a.columnA,
(select b.columnA, b.columnB
from tableA b
where b.columnA = a.columnA
for xml path, root
) as myXml
from tableA a
)
select * from myTable
我被 XML 迷住了,以至于我沒有看到我需要在表上使用 2 個別名進行自聯接!
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/415067.html
標籤:
上一篇:需要根據重量百分比計算成本
下一篇:過濾并執行多個計算
