1

次の形式のテーブルがあります。

| ID    | COURSE | PASS |
---------------------------
| 1     | 1      | 1      |
| 1     | 2      | 1      |    
| 1     | 3      | 1      |
| 1     | 4      | 0      |
| 1     | 5      | 0      |

そして、次の形式で行が必要です:

| ID    | FAILED | PASSED |
---------------------------
| 1     | 4,5    | 1,2,3  |

私が考え出したのは次のようなものだけです:

    select NVL(passed.id, failed.id), passed.test, failed.test from 
        (select id, listagg(course, ',') within group (order by course) test from table1 where pass = 1 group by id ) passed 
    full outer join
        (select id, listagg(course, ',') within group (order by course) test from table1 where pass = 0 group by id ) failed
    on passed.id = failed.id

単一のクエリでそれを行う方法はありますか?

4

1 に答える 1