执行查询时,一个表的列值应为列标题



我有两个表:pet类型

Id 类型B
1
2 cat
3

使用pivot如下

SELECT *
FROM
(
select Ownerid,TypeB from Ownerstable o
join pettype p
on p.Id=o.Pettype
) d  
PIVOT
(
count(TypeB)
FOR TypeB IN ([cat],[dog],[snake])
) p

相关内容

最新更新