sql - Concat 2 column data through another column (group by) -
my table - education
state code descr aa 001 aaaaaa aa 002 aaaabbb bb 003 qwerty cc 025 asdfg bb 014 zsedc aa 015 lknhj cc 084 uhygt cc 067 fdrda
i want in below format:
state code
aa 001-aaaaaa,002-aaaabbb,015-lknhj bb 003-qwerty,014-zsedc** cc 025-asdfg,084-uhygt,067-fdrda
i trying , succeded in getting column "code" in single row below query:
select state, replace(wm_concat(code), ',', ',') code education group state order state;
output:
state code aa 001,002,015 bb 003,014 cc 025,084,067
and have got respective descr
each code
through below query:
select state, concat(concat(replace(wm_concat(code),',',','), '-'),descr) code education group state,descr order state
can me club-up queries desired output.
thank in advance.
wont ?
select state, replace(wm_concat(code||'-'||descr), ',', ',') code education group state order state;
if oracle 11g, can be
select state, listagg(code||'-'||descr,',') (within group order code) code education group state order state;
Comments
Post a Comment