不带聚合函数的Pivot或Oracle中按组排列的列

ass*_*l.d 4 sql oracle pivot aggregate

我试图按行的类型将行转换为列.
这里给出了Table_1 Table_1

           Table_1
CITY            AMOUNT      TYPE_ID
Moscow         158000          1
New York       94500           1
Moscow         1478000         2
Los Angeles    162000          2
New York       5500000         2
Los Angeles    35400           1
Moscow         741200          1
Run Code Online (Sandbox Code Playgroud)

并且在结果中使用select脚本我想在Table_2 Table_2中使用

            Table_2
CITY           TYPE_1_AMOUNT       TYPE_2_AMOUNT
Moscow           158000               1478000
Moscow           741200                  NULL
New York         94500                5500000
Los Angeles      35400                162000
Run Code Online (Sandbox Code Playgroud)

我试过PIVOT.但必须有聚合函数.
聚合函数MAX()仅检索最大量...

Dav*_*itz 6

select      city
           ,min (case type_id when 1 then amount end)   as type_1_amount
           ,min (case type_id when 2 then amount end)   as type_2_amount

from       (select      city,type_id,amount

                       ,row_number () over 
                        (
                            partition by    city,type_id
                            order by        amount
                        ) as rn

            from        Table_1
            )

group by    city
           ,rn

order by    city
           ,rn               
Run Code Online (Sandbox Code Playgroud)
+-------------+---------------+---------------+
| CITY        | TYPE_1_AMOUNT | TYPE_2_AMOUNT |
+-------------+---------------+---------------+
| Los Angeles | 35400         | 162000        |
+-------------+---------------+---------------+
| Moscow      | 158000        | 1478000       |
+-------------+---------------+---------------+
| Moscow      | 741200        | (null)        |
+-------------+---------------+---------------+
| New York    | 94500         | 5500000       |
+-------------+---------------+---------------+
Run Code Online (Sandbox Code Playgroud)