Select Rows As Column in SELECT(在 SELECT 中选择行作为列)
问题描述
可能重复:
如何选择列作为行?
我有一张带有 ID 的表格,例如
I have a table with ID's, like
Table
-------
1
2
3
4
5
and so on
我有这个问题,
SELECT A,B,这里我需要选择 Id 作为列,FROM MyTable
SELECT A,B,Here I need To SELECT the Id's as Column, FROM MyTable
所以结果是,
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 中选择行作为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 SELECT 中选择行作为列


基础教程推荐
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01