Oracle
 sql >> Datenbank >  >> RDS >> Oracle

Pivot in Oracle 11g

Du warst nah dran:

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)
);