我正在寻找一种在oracle中将行转换为列的有效方法,我需要处理大量的记录。 [英] I'm looking for an efficient way to convert rows to columns in oracle, and I need to deal with lot of records.

查看:70
本文介绍了我正在寻找一种在oracle中将行转换为列的有效方法,我需要处理大量的记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< TD> Testing2 < TD> Testing12
<强>日期 <强>代码 <强>日期< /强>
Testing1 XYZ 2018年5月21日
XYZ 2018年5月21日
Testing3 XYZ 2018年5月22日
Testing4 XYZ 2018年5月22日
Testing5 XYZ 2018年5月22日
Testing6 XYZ 2018年5月23日
Testing7 XYZ 2018年5月23日
Testing8 XYZ 2018年5月24日
Testing9 XYZ 2018年5月24日
Testing10 XYZ 2018- 05-24
Testing11 XYZ 2018年5月25日
XYZ 2018年5月25日
Testing13 XYZ 2018年5月26日
Testing14 XYZ 2018年5月26日
Testing15 XYZ 2018-05-27
Testing16 XYZ 2018年5月27日
Testing17 XYZ 2018- 05-27


i需要以下数据





< TD>&NBSP;
2018-05-21 2018-05-22 2018-05-23 2018年5月24日 2018年5月25日 2018年5月26日 2018年5月27日
Testing1 Testing3 Testing6 Testing8 Testing11 Testing13 Testing15
Testing2 Testing4 Testing7 Testing9 Testing12 Testing14 Testing16
&NBSP; Testing5 Testing10 &NBSP; &NBSP; Testing17




我的尝试:



怎么样实现这一点我已经尝试了PIVOT但是列标题(日期)没有修复,需要从用户选择的日期显示7日期的数据

请帮帮我谢谢你

DateCodeDate
Testing1XYZ2018-05-21
Testing2XYZ2018-05-21
Testing3XYZ2018-05-22
Testing4XYZ2018-05-22
Testing5XYZ2018-05-22
Testing6XYZ2018-05-23
Testing7XYZ2018-05-23
Testing8XYZ2018-05-24
Testing9XYZ2018-05-24
Testing10XYZ2018-05-24
Testing11XYZ2018-05-25
Testing12XYZ2018-05-25
Testing13XYZ2018-05-26
Testing14XYZ2018-05-26
Testing15XYZ2018-05-27
Testing16XYZ2018-05-27
Testing17XYZ2018-05-27

i need the data like below


2018-05-212018-05-222018-05-232018-05-242018-05-252018-05-262018-05-27
Testing1Testing3Testing6Testing8Testing11Testing13Testing15
Testing2Testing4Testing7Testing9Testing12Testing14Testing16
 Testing5 Testing10  Testing17


What I have tried:

how to achieve this i have tried PIVOT but the columns headers(Date) are not fixed, need to display the 7 date's data from user selected date
please help me thank u

推荐答案

我仍然会使用PIVOT但是因为你不知道列标题直到运行时你需要编写一些动态SQL - 参见编码动态SQL语句 [ ^ ]
I would still use PIVOT but because you don't know the column headers until run-time you need to program some "dynamic SQL" - See Coding Dynamic SQL Statements[^]


这篇关于我正在寻找一种在oracle中将行转换为列的有效方法,我需要处理大量的记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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