伙计我有一点问题 我希望通过枢轴中的id排序数据.. 你可以通过fiddle
试试谢谢
答案 0 :(得分:0)
问题似乎是在Person_Id
声明中使用了COUNT()
。以下作品:
SELECT Person_Id, Name,
[Honda], [Suzuki], [Yamaha], [Harley Davidson]
FROM (SELECT P.Name, PM.MotorCycle, PM.Person_id
FROM Person P LEFT JOIN
dbo.Person_MotorCycle PM
ON P.Person_Id = PM.Person_Id
) AS ST
PIVOT (COUNT(MotorCycle)
FOR MotorCycle IN
([Honda], [Suzuki], [Yamaha], [Harley Davidson]
)
) PIV
ORDER BY Person_Id;