Hello all, I have a table in Oracle 10g that contains some information as follows:
SQL> select * from t_test;
INFO CODIGO GRUPO
---------- ---------- ----------
101 190 VTOS
100 130 VTOS
102 140 VTOS
I'd like to extract all the rows that have GRUPO='VTOS' and transpose those rows to columns. The values in CODIGO are predetermined(I know which values can be stored in that column), so would like to get something like this:
INFO_190 INFO_130 INFO_140
-------- -------- --------
101 100 102
I know I can do it with some subqueries, for example:
SELECT (SELECT info
FROM t_test
WHERE codigo = 190 AND grupo = 'VTOS') info_190,
(SELECT info
FROM t_test
WHERE codigo = 130 AND grupo = 'VTOS') info_130,
(SELECT info
FROM t_test
WHERE codigo = 140 AND grupo = 'VTOS') info_140
FROM DUAL
but I'd like to find a more efficient way. Can anyone suggest how to do it?