答案 0 :(得分:2)
您想要条件聚合:
select LocID, AuditID,
max(case when Seq = 1 then userID end) User1,
max(case when Seq = 2 then userID end) User2,
max(case when Seq = 3 then userID end) User3,
max(case when Seq = 4 then userID end) User4,
max(case when Seq = 5 then userID end) User5
from (select *,
row_number() over (partition by LocID, AuditID order by userID) Seq
from table a
) t
group by LocID, AuditID;
答案 1 :(得分:-3)
您可以使用group_concat功能SQL服务器。
通过LocID,AuditID
从表组中选择LocID,AuditID,group_concat(userID)listUser稍后您可以使用listUser列值显示在表
中