2011-09-15 17 views
6

我有這樣的說法,結合多行成一個,然後輸出它的方式,我需要的數據:甲骨文合併多行成一個具有鮮明的標題

SELECT COURSES_ID, REQUISITE_TYPE_TITLE 
      , RTRIM 
      (xmlagg (xmlelement (c, CONDITION_TITLE || '' || REQ_TEXT || '' ) order by ORDER_NUM).extract ('//text()') 
      , ',') AS REQTexts 
    FROM COS_REQUISITES 
    WHERE COURSES_ID = '1175' 
    AND REQUISITE_TYPE_TITLE != 'Corequisite' 
    GROUP BY COURSES_ID, REQUISITE_TYPE_TITLE; 

結果:

╔═══════════╦════════════╦═════════════════════════════════════╦═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗ 
║ ORDER_NUM ║ COURSES_ID ║  REQUISITE_TYPE_TITLE   ║                                       REQ_TEXT                                       ║ 
╠═══════════╬════════════╬═════════════════════════════════════╬═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣ 
║   1 ║  1175 ║ Limitation on Enrollment   ║ With minimum grade of "C"                                                                       ║ 
║   2 ║  1175 ║ Advisory on Recommended Preparation ║ MATH 200 or equivalent college course with "C" or better or equivalent college course with "C" or better or MATH 205 or equivalent college course with "C" or better or or equivalent college course with "C" or better or equivalent college course with "C" or better ║ 
╚═══════════╩════════════╩═════════════════════════════════════╩═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝ 

結構:

╔═══════════╦════════════╦═══════════╦═════════════════════════════════════╦══════════════════════════════════════════════════════════╗ 
║ ORDER_NUM ║ COURSES_ID ║ CONDITION ║  REQUISITE_TYPE_TITLE   ║       REQ_TEXT       ║ 
╠═══════════╬════════════╬═══════════╬═════════════════════════════════════╬══════════════════════════════════════════════════════════╣ 
║  1164 ║  1175 ║   ║ Advisory on Recommended Preparation ║ MATH 200 or equivalent college course with "C" or better ║ 
║  1165 ║  1175 ║   ║ Advisory on Recommended Preparation ║ or equivalent college course with "C" or better  ║ 
║  1166 ║  1175 ║ or  ║ Advisory on Recommended Preparation ║ MATH 205 or equivalent college course with "C" or better ║ 
║  1167 ║  1175 ║ or  ║ Advisory on Recommended Preparation ║ or equivalent college course with "C" or better  ║ 
║  1168 ║  1175 ║   ║ Advisory on Recommended Preparation ║ or equivalent college course with "C" or better  ║ 
║  1169 ║  1175 ║   ║ Limitation on Enrollment   ║ With minimum grade of "C"        ║ 
╚═══════════╩════════════╩═══════════╩═════════════════════════════════════╩══════════════════════════════════════════════════════════╝ 

通緝的結果:

╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗ 
║ Advisory on Recommended Preparation MATH 200 or equivalent college course with "C" or better or equivalent college course with "C" or better or MATH 205 or equivalent college course with "C" or better or equivalent college course with "C" or better or equivalent college course with "C" or better Limitation on Enrollment With minimum grade of "C" ║ 
╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝ 

我試圖避免必須把這個臨時表或多個視圖,這將輸出到一個部分。

我知道它有不好的數據,但我被告知垃圾進出垃圾。任何幫助將不勝感激。

即使LISTAGG它不允許不同,據我可以告訴:

SELECT COURSES_ID,LISTAGG(REQUISITE_TYPE_TITLE || '' || CONDITION_TITLE || '' || REQ_TEXT「 ')WITHIN GROUP(ORDER BY ORDER_NUM)AS標題FROM COS_REQUISITES WHERE COURSES_ID ='1175' GROUP BY COURSES_ID;

結果:

╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗ 
║                                                                TITLE                                                                ║ 
╠════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╣ 
║ Advisory on Recommended Preparation MATH 200 or equivalent college course with "C" or better Advisory on Recommended Preparation or equivalent college course with "C" or better Advisory on Recommended Preparation or MATH 205 or equivalent college course with "C" or better Advisory on Recommended Preparation or or equivalent college course with "C" or better Advisory on Recommended Preparation or equivalent college course with "C" or better Limitation on Enrollment With minimum grade of "C" ║ 
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝ 

通知的REQUISITE_TYPE_TITLE重複,我只希望它一旦出現像通緝的結果。我無法修改表讓它們爲空,因爲這是一個表被動態加載並由其他人每天更新。

+3

哇,僞圖!好久不見! (在我的遠程管理器安裝之外,就是這樣)。我會假裝我正在寫一個有用的,寫得很好的插圖問題,而不是單獨使用這些漂亮的表格。 :) –

+1

哈哈謝謝...我發現這個鏈接對此很有幫助: http://www.sensefulsolutions.com/2010/10/format-text-as-table.html 因此,將數據複製到excel放在表中標題等。選擇Unicode藝術和你的完成。另外如圖所示:http://webapps.stackexchange.com/questions/6700/is-there-a-webapp-to-create-ascii-art-tables 和 http://meta.stackexchange.com/questions/ 83009/do-you-know-any-online-tool-that-c​​reating-ascii-tables-for-proper-use-on-stack-exc – AhsenB

+0

多麼偉大的工具,謝謝! –

回答

1

有點亂,但應該得到你問什麼

SELECT 
COURSES_ID, 
RTRIM (xmlagg (xmlelement (c, REQUISITE_TYPE_TITLE || '' || REQTexts || '' ) order by mino).extract ('//text()'), ',') AS REQTexts 
FROM 
(
SELECT 
COURSES_ID, REQUISITE_TYPE_TITLE, MIN (ORDER_NUM) mino, 
RTRIM (xmlagg (xmlelement (c, CONDITION_TITLE || '' || REQ_TEXT || '' ) order by ORDER_NUM).extract ('//text()') , ',') AS REQTexts 
FROM COS_REQUISITES 
WHERE COURSES_ID = '1175' 
AND REQUISITE_TYPE_TITLE != 'Corequisite' 
GROUP BY COURSES_ID, REQUISITE_TYPE_TITLE 
) 
GROUP BY COURSES_ID;