2016-07-15 48 views
-1

我運行,返回2行如何把2行從查詢返回到成單排2列在Oracle SQL

SELECT a FROM TABLE-A WHERE condition=something; 

ROW1值1

2行值2

查詢

現在,我希望把它放在一個新表中單列的2列

SELECT column1, column2 FROM TABLE-B WHERE condition=something; 

ROW1列1列2

value1 value2 

能否請你幫我這個?

+0

想你正在尋找樞軸。 http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html –

回答

0

目前還不清楚要如何挑選哪一行進入哪一列 - 這裏有幾個選項:

SELECT MIN(a) AS minimum_value, 
     MAX(a) AS maximum_value 
FROM table_a 
WHERE 1=1; 

SELECT MAX(a) KEEP (DENSE_RANK FIRST ORDER BY ROWNUM) AS first_value, 
     MAX(a) KEEP (DENSE_RANK LAST ORDER BY ROWNUM) AS last_value 
FROM table_a 
WHERE 1=1; 

SELECT * 
FROM (SELECT a, ROWNUM AS rn FROM table_a WHERE 1=1) 
PIVOT (MAX(a) FOR rn IN (1 AS first_value, 2 AS second_value)); 
+0

這工作!太棒了,謝謝你! – harry0023