Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Oracle将多行合并为一行,并具有不同的标题_Sql_Database_Oracle - Fatal编程技术网

Sql Oracle将多行合并为一行,并具有不同的标题

Sql Oracle将多行合并为一行,并具有不同的标题,sql,database,oracle,Sql,Database,Oracle,我有这样一条语句,它将多行合并为一行,然后以我需要的方式输出数据: SELECT COURSES_ID, REQUISITE_TYPE_TITLE , RTRIM ( xmlagg (xmlelement (c, CONDITION_TITLE || '' || REQ_TEXT || '' ) order by ORDER_NUM).extract ('//text()') , ',' ) AS REQTexts

我有这样一条语句,它将多行合并为一行,然后以我需要的方式输出数据:

 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 ║
╚═══════════╩════════════╩═════════════════════════════════════╩═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║                                                                                                                                                                                                                                                             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" ║
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
结构:

╔═══════════╦════════════╦═══════════╦═════════════════════════════════════╦══════════════════════════════════════════════════════════╗
║ 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" ║
╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
我试图避免把它放到一个临时表或多个视图中,而这些临时表或视图会将它输出到一个部分中

我知道它有坏数据,但我被告知垃圾输入,垃圾输出。任何帮助都将不胜感激

就我所知,即使Listag不允许使用distinct:

选择课程ID,列表标签(必选类型标题)|| 组内的条件|标题|‘| |要求|文本’)(按顺序 订单号)作为课程ID为'1175'的COS_必要条件的标题 按课程编号分组

结果:

╔═══════════╦════════════╦═════════════════════════════════════╦═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ 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 ║
╚═══════════╩════════════╩═════════════════════════════════════╩═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
╔════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║                                                                                                                                                                                                                                                             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" ║
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
请注意,必要的_TYPE_标题重复出现,我只希望它像所需的结果一样显示一次。我无法修改该表使其为空,因为这是一个由其他人每天动态加载和更新的表。

尝试使用listag()函数

例如:


Hth有点凌乱,但应该会满足你的要求

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;

哇,伪图形!好久不见!(也就是说,在我的Far Manager安装之外)我会假装我正在回答一个有用的、写得好的、有插图的问题,而不仅仅是这些漂亮的表格哈哈,谢谢。。。我发现这个链接有助于实现这一点:所以将数据复制到excel,放入表格标题等。选择Unicode艺术,然后完成。同样如图所示:我已经试过了,但它没有明确的必要类型标题,或者我似乎无法理解这一部分。