2011-09-15 2 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_NUM) AS 제목 COS_REQUISITES COURSES_ID ='1175 ' GROUP BY COURSES_ID;

결과 : REQUISITE_TYPE_TITLE 반복, 나는 단지 그것을 원하는 결과처럼 한 번에 표시 할

╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗ 
║                                                                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" ║ 
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝ 

알 수 있습니다. 이 테이블은 동적으로로드되고 매일 다른 사람이 업데이트하기 때문에 null이되도록 테이블을 수정할 수 없습니다.

+3

와우,으로 pseudographics 요청 무엇을 양보해야한다() 함수

예 :! 오랜만 이네! (Far Manager 설치 외에는.) 필자는 유용하고 잘 쓰여진 질문에 +1하고이 아름다운 테이블 만 혼자만은 사용하지 않는 척 할 것입니다. :) –

+1

lol thanks ...이 링크는 다음 작업에 유용합니다. http://www.sensefulsolutions.com/2010/10/format-text-as-table.html 데이터를 복사하여 테이블에 저장하십시오. 헤더 등 유니 코드 아트를 선택하고 완료되었습니다. 또한 그림과 같이 : 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-any-online-tools-that-ascii-tables-for-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;