ORACLE/SQL:wm_concat &订购方式

ORACLE/SQL: wm_concat amp; order by(ORACLE/SQL:wm_concat amp;订购方式)

本文介绍了ORACLE/SQL:wm_concat &订购方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 ODBC 和 Crystal Reports 2008 使用 oracle 11(不确定确切版本,但由于 LISTAGG 不起作用,我想它不是第 2 版).

I'm using oracle 11 (not sure about the exact version, but since LISTAGG doesn't work, I suppose it's not release 2) through ODBC and crystal reports 2008.

这是我遇到的问题:

这是一张表格:

TABLE ODB.TASK_CARD_CONTROL  
------------------------------------------  
task_card     control_category     code  
------------------------------------------  
1                  zone             17  
1                  zone             33  
1                  zone             21  
2                  zone             18  
2                  zone             05  
3                  zone             55  
3                  zone             32  
3                  zone             72 

我正在使用 WM_CONCAT 函数来获得这样的东西:

I'm using the WM_CONCAT function to obtain something like this:

task_card      zones
1              17,33,21
2              18,05
3              55,32,72

这里是 SQL:

SELECT TASK_CARD, WM_CONCAT(code) as ZONES
FROM ODB.TASK_CARD_CONTROL
WHERE ODB.TASK_CARD_CONTROL.CONTROL_CATEGORY = 'ZONE'
GROUP BY TASK_CARD

但我希望对区域进行排序,所以我尝试了这个:

but I'd like the zones to be sorted, so I tried this:

SELECT TASK_CARD, WM_CONCAT(code) as ZONES
FROM (SELECT TASK_CARD, CODE, CONTROL_CATEGORY FROM ODB.TASK_CARD_CONTROL 
ORDER BY CODE)
WHERE ODB.TASK_CARD_CONTROL.CONTROL_CATEGORY = 'ZONE'
GROUP BY TASK_CARD

但由于某种原因,它返回以下错误:

but for some reason, it returns the following error:

Failed to retrieve data from the database.
Details: 42S22:[Oracle][ODBC][Ora]ORA-00904: 
"ODB"."TASK_CARD_CONTROL"."CONTROL_CATEGORY" : invalid identifier

我真的不明白我在这里做错了什么......有人可以给我一个提示吗?

I really don't understand what I'm doing wrong here... Can anybody give me a hint ?

推荐答案

您不能从内部查询外部引用 ODB.TASK_CARD_CONTROL.CONTROL_CATEGORY.试试:

You can't reference ODB.TASK_CARD_CONTROL.CONTROL_CATEGORY from outside the inner query. Try:

SELECT TASK_CARD, WM_CONCAT(code) as ZONES
FROM (SELECT TASK_CARD, CODE, CONTROL_CATEGORY FROM ODB.TASK_CARD_CONTROL 
      WHERE ODB.TASK_CARD_CONTROL.CONTROL_CATEGORY = 'ZONE'
      ORDER BY CODE)
GROUP BY TASK_CARD

这篇关于ORACLE/SQL:wm_concat &订购方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:ORACLE/SQL:wm_concat &订购方式

基础教程推荐