Difference between revisions of "SQL - Group several lines in the same column with LIST TAG"

From GUILLARD WIKI
Jump to navigation Jump to search
(Created page with "<syntaxhighlight lang="sql"> select ost_pid_facility, listagg( ('COL: '||trim(mic_txt_mis_value)||' OST: '||trim(ost_nme_alias)) , ', ' ) WITHIN GROUP (ORDER BY ost_pid_f...")
 
Line 1: Line 1:
<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
 
SELECT country,  
select ost_pid_facility,
LISTAGG(first_name, ', ') WITHIN GROUP (order by first_name)  
listagg(
FROM tablename
  ('COL: '||trim(mic_txt_mis_value)||' OST: '||trim(ost_nme_alias)) ,
GROUP BY country
  ', '
)
WITHIN GROUP (ORDER BY ost_pid_facility DESC) "COL OST"
from vls_mis_code
inner join vls_fam_global1 on gb1_cde_code = mic_cde_mis_type
inner join vls_outstanding on ost_rid_outstandng = mic_pid_product_id
where mic_cde_mis_type = 'NGCOL' and mic_cde_prod_type = 'LOAN'
group by ost_pid_facility
 
</syntaxhighlight>
</syntaxhighlight>

Revision as of 16:45, 3 May 2018

SELECT country, 
LISTAGG(first_name, ', ') WITHIN GROUP (order by first_name) 
FROM tablename 
GROUP BY country