Tony Wolff
Tony Wolff

Reputation: 742

Pivoting a column in oracle

I have a table with 4 columns name, gender, age and hair_color. hair_color has 3 options Blond, Black and Brown.

Can I use the pivot command to generate a table with columns name, gender, age, blond, black and brown with the same number of rows.

Upvotes: 0

Views: 44

Answers (1)

tkalatz
tkalatz

Reputation: 36

select *
from FOURCOLUMNTABLE
pivot (
  count(HAIR_COLOR) as HC
  for HAIR_COLOR in ('Blond','Black','Brown')
)

Upvotes: 1

Related Questions