这是我在 mssql 下面的查询
declare @cars as table (
owners tinyint,
attribute varchar(20),
value varchar(20)
)
insert into @cars(owners, attribute, value)
values (1, 'Make', 'VW'),
(1, 'Model', 'Rabbit'),
(1, 'Color', 'Gold'),
(1, 'Make', 'V'),
(1, 'Model', 'Rabbi'),
(1, 'Color', 'Goldddd'),
(2, 'Make', 'Jeep'),
(2, 'Model', 'Wrangler'),
(2, 'Color', 'Gray')
select * from @cars
select pvt.owners, pvt.Make, pvt.Model, pvt.Color
from @cars c
pivot (
min(value)
for attribute in ([Make],[Model],[Color])
) pvt
以上回报
业主制作模型颜色
1 v rabbi gold
2 jeep wrangler gray
但我需要像这样回来
业主制作模型颜色
1 v rabbi gold
1 vw rabbit golddd
2 jeep wrangler gray
how is possible?