11 Ağustos 2016 Perşembe

Bir kolon içerisinde tekrarlayan verinin tekilleştirilmesi (distinct)

Önce
------------------------------
 select group_id,   
     listagg(name, ',') within group (order by name) as names  
 from demotable  
 group by group_id   

 group_id names  
 -------- -----  
 1     'Alan, David, David, John'  
 2     'Charles, Julie'  
Sonra
------------------------------

 select group_id,   
 regexp_replace(  
   listagg(name, ',') within group (order by name)  
   ,'([^,]+)(,\1)+', '\1')  
 from demotable  
 group by group_id;   

 group_id names  
 -------- -----  
 1     'Alan, David, John'  
 2     'Charles, Julie'  

Hiç yorum yok:

Yorum Gönder