Select Rows As Column in SELECT [duplicate]

喜你入骨 提交于 2019-12-30 10:07:14

问题


Possible Duplicate:
how to select columns as rows?

I have a table with ID's, like

Table
-------
  1
  2
  3
  4
  5
  and so on

I have this query,

SELECT A,B,Here I need To SELECT the Id's as Column, FROM MyTable

So the Result of this will be,

  A  B  1  2  3  4  5  6  7 and so on
  -----------------------------------

回答1:


You want a cross tab query. Check this out: http://www.simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/

It explains how to do a simple cross tab query which may be all you need. However, it looks like you may also benefit from the stored procedure the writer created to overcome some shortcomings of the cross tab query.




回答2:


You've the answer already in SO :)

See here or here. When you fill the question pay attention, usually it gives you similar questions :)



来源:https://stackoverflow.com/questions/8134063/select-rows-as-column-in-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!