Information to rows in a column

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Wed, 11 Jan 2017 10:03 am

Guys, I'm again asking for a help about SQL ...
Following, I have a spreadsheet as follows..

Code: Select all
Tag - item
01     01
01     02
01     03
02     01
02     02
03     01
03     02
would like to know if there is any way to turn the column " " Tag in a single record, bringing the information in column " " Item in a single-column sorting by ""... thus
Code: Select all
Tag - Item
01     01/02/03
02     01/02
03     01/02
Has how to do so in sql?
Reinaldommo

Poston Wed, 11 Jan 2017 10:12 am

Reinaldo, what version of Oracle you are using?
spernega
Location: São Paulo - SP

Poston Wed, 11 Jan 2017 10:27 am

If it is from the 11 g, there is the LISTAGG.

It would be something like this:
Code: Select all
select TAG
, listagg( CODE,'/') within group (order by TAG)
from TABELA
group by TAG
in my case:
Code: Select all
SQL> select geo_code_id
  2  , LISTAGG(code,'; ') within group (order by CODE) lista
  3  from countries
  4  group by geo_code_id
  5  /

GEO_CODE_ID LISTA
----------- ------------------------------
         21 BEL; FIN; FRA; ITA; USA
         22 HUN; ISL; LUX; NRD
         41 ROM; SVK
         42 AUT; CZE
         81 AUS; NZL
            CHE; DEU; DNK; ESP; GBR; IRL; NLD; NOR; POL; POR; SWE

6 rows selected

SQL>
:-
dr_gori
Location: Portland, OR USA

Thomas F. G

Você já respondeu a dúvida de alguém hoje?
http://glufke.net/oracle/search.php?search_id=unanswered



Return to SQL

Who is online

Users browsing this forum: No registered users and 1 guest