Here is my data:
ID
Model
Year
1
Civic
2008
1
Accord
2010
2
Mustang
2011
3
Tahoe
2011
I would like to get this result:
ID
Model1
Year1
Model2
Year2
1
Civic
2008
Accord
2010
2
Mustang
2011
3
Tahoe
2011
Up to 4 cars can be present under each ID and no more. I have spent a lot of time researching this but have not found a good solution that fits my example exactly. Perhaps because I don’t know how exactly to word my search. Thanks…
There’s not a really great way to do this in SQL. You might try and struggle with a pivot table, but each entity would need a sequence.
Your best bet would be to arrange it how you want in your output language which will have much better tools available for this sort of thing.
Add a column to each row called sequence (which has 1, 2, 3, and 4)