看板 Database 關於我們 聯絡資訊
select Name, isnull([001],0) as [001], isnull([002],0) as [002], isnull([003],0) as [003] from table pivot ( sum(Number) for Location in ([001],[002],[003]) ) as pvt ※ 引述《licheer (Keep The Faith)》之銘言: : 資料庫名稱: MS-SQL : 資料庫版本: VBA : 內容/問題描述: 想要讀右邊的樣子 : Name Location Number Name 001 002 003 : A 001 50 A 50 10 20 : A 002 10 B 30 10 0 : A 003 20 ==> : B 001 30 : B 002 10 : Select : Name, : Number=(Select i.Number From Table as i where i.Locate=001 and i.Name=j.Name), : Number=(Select i.Number From Table as i where i.Locate=002 and i.Name=j.Name), : Number=(Select i.Number From Table as i where i.Locate=004 and i.Name=j.Name) : From Table as j : 上面這樣寫會得到錯誤"子查詢傳回不只1 個值" : 請問要怎麼改呢? : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.223.63.238 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1541745177.A.A3A.html