SELECT 存货编号, [A] as 供应商A价格, [B] as 供应商B价格, [C] as 供应商C价格
FROM
(SELECT 存货编号, 供应商, 价格
FROM 存货表) p
PIVOT
(
sum(价格)
FOR 供应商 IN
( [A], [B], [C])
) AS pvt
ORDER BY 存货编号
SELECT 存货编号, [A] as 供应商A价格, [B] as 供应商B价格, [C] as 供应商C价格
FROM
(SELECT 存货编号, 供应商, 价格
FROM 存货表) p
PIVOT
(
sum(价格)
FOR 供应商 IN
( [A], [B], [C])
) AS pvt
ORDER BY 存货编号
供应商是从表中搜索出来了,刚开始并不知道某存货对应的供应商是哪一些,从搜索结果中只知道某存货 有多少个供应商(记录条数),但搜索结果中有供应商名称。我们一共有两百多个供应商。