How to take a value from one column, and have it expanded with it's own details in the following row in SQL?

25 Views Asked by At

I have the following result set after pulling the details for car prices from a car prices table:

Car ID Price Price adjusted by adjustment amount
1234 $100 5678 -$50
0000 $650
5678 $349

How do I write a SQL function, so that if the price_adjusted_by column has a non-null value (in this case another car ID, 5678, that impacts the price of Car 1234's price by -$50), the row immediately following the Car ID that had an adjustment amount shows the details for 5678, such as the following:

Car ID Price Price adjusted by adjustment amount
1234 $100 5678 -$50
5678 $349
0000 $650
5678 $349

Keep in mind, these cars may have multiple car ID's impacting their price, so if we had two Car ID's impacting the price, the next two rows would show the details for BOTH of the Car ID's impacting the original car ID's price from the original source table?

0

There are 0 best solutions below