這是一個Oracle9i解決方案。 該作業使用查詢中需要CONNECT BY子句的SYS_CONNECT_BY_PATH函數完成。爲了通過某些東西連接行VEHICLE表是「準備好的」......它用curr和prev行號填充。
SELECT
vc.vehicle_class_name,
RTRIM(REPLACE(MAX(SYS_CONNECT_BY_PATH(v.completed,'|')) KEEP (DENSE_RANK LAST ORDER BY v.curr),'|',''),',') completed,
RTRIM(REPLACE(MAX(SYS_CONNECT_BY_PATH(v.incomplete,'|')) KEEP (DENSE_RANK LAST ORDER BY v.curr),'|',''),',') incomplete
FROM
(SELECT
vehicle_class_id,
CASE WHEN status=2 THEN vehicle_id||',' END completed,
CASE WHEN status<>2 THEN vehicle_id||',' END incomplete,
ROW_NUMBER() OVER (PARTITION BY vehicle_class_id ORDER BY vehicle_id) curr,
ROW_NUMBER() OVER (PARTITION BY vehicle_class_id ORDER BY vehicle_id)-1 prev
FROM
vehicle) v JOIN vehicle_class vc
ON v.vehicle_class_id=vc.vehicle_class_id
GROUP BY
vc.vehicle_class_name
CONNECT BY
v.prev=PRIOR v.curr AND v.vehicle_class_id=PRIOR v.vehicle_class_id
START WITH
v.curr=1;
'具有集合函數但不工作的oracle'的情況'。 – user1373028
Oracle9i不再受支持。爲什麼你使用這樣一個過時的版本? –