SQL> with purchase (customer_id, car_product) as
2 (select 123, 'ZINC' from dual union all
3 select 123, 'BLUE' from dual union all
4 select 123, 'RED' from dual union all
5 --
6 select 939, 'BLACK' from dual union all
7 select 939, 'BLUE' from dual
8 )
质询:
9 select customer_id,
10 listagg(car_product, '-') within group
11 (order by case when car_product = 'ZINC' then 'A' else car_product end) as product
12 from purchase
13 group by customer_id;
CUSTOMER_ID PRODUCT
----------- --------------------
123 ZINC-BLUE-RED
939 BLACK-BLUE
SQL>
1条答案
按热度按时间bnlyeluc1#
修复
order by
子句,使其先对ZINC
排序,然后对其余的排序。样本数据:
质询: