Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Pivô no Oracle 11g


Você estava perto:
select age, nvl(male, 0) male, nvl(female, 0) female
from    
(
  select age,  gender,  sum(hours) as hours
  from table1
  group by age, gender
)
pivot
(
  sum(hours) for gender in ('Male' as male, 'Female' as female)
);