I am very new to PL/SQL, but I would like to populate an empty field for all entries in a table, based on the values of several fields in a giving row. So the logic I would like to put in place is, but there are several thing in which I need to keep in mind when setting up a table for a Car Dealership...
First, group by the distinct used_car_ids, then update the column based on.....
- If the used_car_id column is equal to the new_car_id, and both the drive_mode and saftey_rating is 1, then set the Parking_Spot number to 1 as highest precedence.
If the used_car_id column is equal to the new_car_id, but the drive_mode is 1 and saftey_rating is 2, then set the Parking_Spot column to 2 or the available consecutive Parking_Spot number
- If there are more conditions similar to this, but only the saftey_rating is different then, I would like to keep increasing the Parking_Spot number to the next available consecutive Parking_spot number for that entry
If the used_car_id column is equal to the new_car_id, but the drive_mode is 2 and saftey_rating is 1, then set the Parking_Spot column to 3, or the next available Parking_Spot number
- If the used_car_id column is equal to the new_car_id, but the drive_mode is 2 and saftey_rating is 2, then set the Parking_Spot number to 4, or the next available Parking_Spot number
- Same rules apply, as above.
If the highest precedence case isn't met then it should treat the 2 use case as the highest and put that as Parking_Spot=1.
This is a small picture, of what I would ideally want. So as you can see in the picture the Parking Spot number is 1, and 2 depending if the used_car_id, new_car_id, drive_mode, and safety_rating are 1 and 2, but once the used_car_id and new_car_id is different the Parking Spot number increases to 3 and 4.
I'm assuming I need a function to input 4 parameters and based on those fields then I return a number as the Parking Spot. But I am still a bit unsure of how to go about it. Any help would be appreciated. Thanks.