2012-01-28 87 views
0

我有如下因素的數據出從我的查詢提出甲骨文轉換行到列

**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個日期,並且在系統日期處於更改狀態時應該更改

+0

您是否問如何使Oracle的實際結果如下所示?或者如何從Oracle獲取結果集並在您自己的程序輸出中以不同的方式顯示(例如HTML頁面)? – Wyzard 2012-01-28 05:30:09

+0

是的,我想顯示GridView控件aspx文件中的圖像上 – user1103342 2012-01-28 05:35:24

+0

您應該提到的是,在這樣的問題很明顯你問什麼。 (我加了一個asp.net標籤的問題剛纔) – Wyzard 2012-01-28 05:37:07

回答

0

關於做好一切準備如何從行到列在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