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

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

我想谈谈这个:

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

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

解决方法

  1. SELECT a.ID,a.Value AS [Response],b.Value AS [Count]
  2. FROM your_table AS a
  3. INNER JOIN your_table AS b
  4. ON a.ID = b.ID
  5. WHERE a.Name = 'Response'
  6. AND b.Name = 'Count'

猜你在找的MsSQL相关文章