使用查询将行转换为列 [英] convert rows in to columns using query

查看:65
本文介绍了使用查询将行转换为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

日期会议代码[表名称时间表]



2013年1月14日1 CM

2013年1月14日3 CM



从上面我想要输出如下;





1 3 [会话]

1/14/2013 CM CM [代码]





如何获得以上输出在sql server中使用查询。



我该怎么办。请帮助我。



i尝试过以下查询无法正常显示错误,因为1附近的语法不正确。



Date Session Code [Table name Schedule]

1/14/2013 1 CM
1/14/2013 3 CM

From the above i want the output as follows;


1 3 [Session]
1/14/2013 CM CM [Code]


how to get the above output using query in sql server.

how can i do.please help me.

i tried the below query it is not working showing error as Incorrect syntax near ''1''.

 SELECT Date,1,3
FROM Schedule PIVOT (MAX([Code]) FOR Session IN (1,3)) P







如何使用查询得到正确的输出告诉我。




how can i get the correct output using query tell me.

推荐答案

不。



你不能转换使用简单的查询将行转换为列,反之亦然,但是,您可以在代码中轻松执行此操作,遍历行(或列)并在每个步骤中选取另一个的第N个索引每个col(行)。



干杯,

Edo
Nope.

You can''t convert rows into columns and vice versa with a simple query,
however, you can easily do this in your code, iterate through rows (or cols) and on each step pick up the Nth index of the other for each col (row).

Cheers,
Edo


这样......



this way..

SELECT
Date,[1],[3]
FROM
Schedule
PIVOT (MAX([Code]) FOR Session IN ([1],[3])) P



Happy C oding!

:)


Happy Coding!
:)


这篇关于使用查询将行转换为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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