所以你想列出所有的班級教學的校園?對於像
class_id | campus_id
math101 | NY1, PA1
pyt218 | PA1, VA1, NY1
...
的輸出,你可以使用現有的wm_concat功能的Oracle 10g:
with d as (
select 'NY1' as campus_id, 'math101' as class_id from dual union all
select 'PA1' as campus_id, 'math101' as class_id from dual union all
select 'VA1' as campus_id, 'pyt218' as class_id from dual union all
select 'PA1' as campus_id, 'pyt218' as class_id from dual union all
select 'PA1' as campus_id, 'class3' as class_id from dual union all
select 'VA1' as campus_id, 'class3' as class_id from dual union all
select 'VA1' as campus_id, 'math101' as class_id from dual union all
select 'NY1' as campus_id, 'class3' as class_id from dual
)
select class_id, wm_concat(campus_Id)
From d
group by class_id
在Oracle 11.2,也可以用來產生相同結果的新功能「LISTAGG」 :
with d as (
select 'NY1' as campus_id, 'math101' as class_id from dual union all
...
)
select class_id, listagg(campus_id, ',') within group (order by campus_id)
From d
group by class_id
這對我來說看起來是正確的,是什麼問題? – Bob 2015-03-31 01:14:21
問題是math101例如可能會在NY1和PA1校區中教授。 – 2015-03-31 03:57:46
這將是class_campus表中的兩個條目。一個用於NY1的math101和一個用於PA1的math101。您將使表中的class_id和campus_id唯一。你目前的樣本有兩次與PA1連接的pyt218,我認爲這不是有效的。如果是這樣,請解釋。 – Bob 2015-03-31 12:29:44