甲骨文转换行到列
问题描述:
我有如下因素的数据出从我的查询提出甲骨文转换行到列
**Date** **HIGH** **LOW** **IMAGE** **TYPE**
1/28/2012 69 42 1.jpg SUN
1/29/2012 70 42 2.jpg MSUN
我想这个输出转换成
**1/28/2012** **1/29/2012**
1.jpg 2.jpg
Sun MSUN
69 72
42 42
这里是我的查询
SELECT
W_DATE,HIGH, LOW,
W_TYPE, IMAGE
FROM WEATHER
ORDER BY W_DATE ASC
,也我在行中有多个日期,我只想显示4个日期,并且在系统日期处于更改状态时应该更改
答
关于做好一切准备如何从行到列在Oracle中,你可以在这里读到:
http://www.dba-oracle.com/t_converting_rows_columns.htm
我没有看到,从来看数据库点直接的解决方案 - 建议在应用程序端做格式化,否则它可能看起来像这样蹩脚:
SELECT
to_char(w1.w_Date,'MM/DD/YYYY'), to_char(w2.w_Date,'MM/DD/YYYY'),
to_char(w3.w_Date,'MM/DD/YYYY'), to_char(w4.w_Date,'MM/DD/YYYY')
FROM
(select * from weather where w_date = trunc(sysdate)) w1,
(select * from weather where w_date = trunc(sysdate) + 1) w2,
(select * from weather where w_date = trunc(sysdate) + 2) w3,
(select * from weather where w_date = trunc(sysdate) + 3) w4
UNION ALL
SELECT
w1.image, w2.image, w3.image , w4.image
FROM
(select * from weather where w_date = trunc(sysdate)) w1,
(select * from weather where w_date = trunc(sysdate) + 1) w2,
(select * from weather where w_date = trunc(sysdate) + 2) w3,
(select * from weather where w_date = trunc(sysdate) + 3) w4
UNION ALL
SELECT
w1.w_type, w2.w_type, w3.w_type , w4.w_type
FROM
(select * from weather where w_date = trunc(sysdate)) w1,
(select * from weather where w_date = trunc(sysdate) + 1) w2,
(select * from weather where w_date = trunc(sysdate) + 2) w3,
(select * from weather where w_date = trunc(sysdate) + 3) w4
UNION ALL
SELECT
to_char(w1.high), to_char(w2.high), to_char(w3.high) , to_char(w4.high)
FROM
(select * from weather where w_date = trunc(sysdate)) w1,
(select * from weather where w_date = trunc(sysdate) + 1) w2,
(select * from weather where w_date = trunc(sysdate) + 2) w3,
(select * from weather where w_date = trunc(sysdate) + 3) w4
UNION ALL
SELECT
to_char(w1.low), to_char(w2.low), to_char(w3.low) , to_char(w4.low)
FROM
(select * from weather where w_date = trunc(sysdate)) w1,
(select * from weather where w_date = trunc(sysdate) + 1) w2,
(select * from weather where w_date = trunc(sysdate) + 2) w3,
(select * from weather where w_date = trunc(sysdate) + 3) w4;
/
+1
汤姆凯特的回答也可能是有用的:http://asktom.oracle.com/pls/ ?asktom/F p = 100:11:5331044584595759 :::: P11_QUESTION_ID:4031849343543#11288826016365 – 2012-01-28 12:20:23
您是否问如何使Oracle的实际结果如下所示?或者如何从Oracle获取结果集并在您自己的程序输出中以不同的方式显示(例如HTML页面)? – Wyzard 2012-01-28 05:30:09
是的,我想显示GridView控件aspx文件中的图像上 – user1103342 2012-01-28 05:35:24
您应该提到的是,在这样的问题很明显你问什么。 (我加了一个asp.net标签的问题刚才) – Wyzard 2012-01-28 05:37:07