tsql – T-SQL – 如何交换行和列

前端之家收集整理的这篇文章主要介绍了tsql – T-SQL – 如何交换行和列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这样的结果集结构
ID       Value      Name
1       Oranges     Reponse
1       42      Count
2       Apples      Reponse
2       65      Count
3       Figs        Reponse
3       74      Count

我想谈谈这个:

ID     Response       Count
1       Oranges     42
2       Apples      65
3       Figs        74

使用sql.有没有办法做到这一点?谢谢!

解决方法

SELECT a.ID,a.Value AS [Response],b.Value AS [Count]
FROM your_table AS a
    INNER JOIN your_table AS b
        ON a.ID = b.ID
WHERE a.Name = 'Response'
    AND b.Name = 'Count'
原文链接:https://www.f2er.com/mssql/83549.html

猜你在找的MsSQL相关文章