在SELECT中选择行作为列 [英] Select Rows As Column in SELECT

查看:92
本文介绍了在SELECT中选择行作为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何将列选择为行?

Possible Duplicate:
how to select columns as rows?

我有一个ID为ID的表格,例如

I have a table with ID's, like

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

我有这个查询

选择A,B,在这里,我需要从MyTable中选择ID作为列

因此,结果将是

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

推荐答案

您要使用交叉表查询.检查一下: http://www.simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/

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.

这篇关于在SELECT中选择行作为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆