sql >> Database >  >> RDS >> Oracle

Oracle LISTAGG() voor meerdere attributen?

select K, listagg(case when chgv1 = 1 then v1 else null end,',') within group (order by v1) as v1lst, --Only consider cases in listagg when rows have changed
          listagg(case when chgv2 = 1 then v2 else null end,',') within group (order by v2) as v2lst  --Only consider cases in listagg when rows have changed
from (
 select k, v1, v2,
        row_number() over (partition by k,v1 order by v1 ) as chgv1, --Detect changes in v1. In this case it's 1.
        row_number() over (partition by k,v2 order by v1 ) as chgv2  --Detect changes in v1. In this case it's 1.
 from t)
group by k;


  1. Prestaties afstemmen van Oracle

  2. 7 manieren om uw Oracle-versie te controleren

  3. MySQL-query:match door komma's gescheiden waarde met kolom met door komma's gescheiden tekenreeks

  4. MySql op cascade-concept verwijderen?