Re: [SQL ] 每个Field都要做SubQuery

楼主: cutekid (可爱小孩子)   2018-11-09 14:32:55
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 个值"
: 请问要怎么改呢?
: 谢谢

Links booklink

Contact Us: admin [ a t ] ucptt.com