您想取消行到列的IVOT。最佳解决方案取决于正在运行的数据库。跨数据库的方法是 union all :
select claimID, error1 as error from mytable
union all select claimID, error2 from mytable
union all select claimID, error3 from mytable
union all select claimID, error4 from mytable
在支持横向连接和 values() 行构造函数中,有更好的选项,不需要多次扫描表。 博士后:
select x.*
from mytable t
cross join lateral (values
(t.claimID, t.error1),
(t.claimID, t.error2),
(t.claimID, t.error3),
(t.claimID, t.error4)
) as x(claimID, error)
1条答案
按热度按时间qco9c6ql1#
您想取消行到列的IVOT。最佳解决方案取决于正在运行的数据库。跨数据库的方法是
union all
:在支持横向连接和
values()
行构造函数中,有更好的选项,不需要多次扫描表。博士后:
在sql server中,您只需替换
cross join lateral
与cross apply
.