Students may have more than one race.I want to add races to report with new headings: Race1, Race2 and Race3 only.

```
select
s.lastfirst, s.grade_level,
max(case when sr.racecd = 100 then 100 else 0 end)race100,
max(case when sr.racecd = 201 then 201 else 0 end)race201,
max(case when sr.racecd = 300 then 300 else 0 end)race300,
max(case when sr.racecd = 400 then 400 else 0 end)race400,
max(case when sr.racecd = 600 then 600 else 0 end)race600,
max(case when sr.racecd = 700 then 700 else 0 end)race700
from students s, studentrace sr
where s.enroll_status=0
and s.id=sr.studentid
group by s.lastfirst,s.grade_level
order by s.grade_level ASC
```

## Best Answer

This needs a variation, here pivoting can be done using a

`ROW_NUMBER`

: