sql >> Databasteknik >  >> RDS >> Oracle

Oracle LISTAGG() för flera attribut?

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. Hur ignorerar man SequelizeUniqueConstraintError i Sequelize?

  2. MySQL / Classic ASP - Parameteriserade frågor

  3. MySQL Trigger-fråga:trigger bara när en kolumn ändras?

  4. Hur får man fram räkningen av varje distinkt värde i en kolumn?