I have a schema like:
[ad_id] . [name] . [valueofname]
1 . name . "brian"
1 . age . "23"
2 . job . "IT"
2 . name . "Jack"
the row name contains multiple values : age
, name
, birthday
, job
, age
I'd like to convert it into this:
[ad_id] . [name] . [age] . [birthday] . [job]
[valueofname] [valueofname] [valueofname] [valueofname]
I have done the query for each line:
select * from where name='name'
select * from where name='age'
select * from where name='job'
I saw the example SQL Server : Columns to Rows. But it's the opposite of my problem.
Do you have any suggestion for making one scalable query in term of performance?
You can use conditional aggregation:
In SQL Server, you can also do something similar with
pivot
.