0

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • For example, if I were to put this as a logical statement, it would be something like this: CASE WHEN adjustment_amount IS NOT null THEN make the next row show the details for the Car ID in the price_adjusted_by column. – tiredallthetime Apr 19 '22 at 03:16
  • 1) Which dbms are you using? 2) `these cars may have multiple car ID's impacting their price` Can you add more data to the samples above that show an example of this? Also, what do you mean by "impacting their price"? In the samples above, you're just displaying a specific car row after another, but the price column is still the same. – SOS Apr 19 '22 at 04:02

0 Answers0