3

My data looks like this.

enter image description here

The output I am looking to see is:

enter image description here

Here is a query I wrote which is not quite there yet but I know the logic of what I should be doing. I need to take the max value of column(rate) of the same vehicle_size and competitor. This could be written in a better way so I would appreciate it if someone can point me to the right direction.

Below is my query:

SELECT RENTAL_DATE, OUTBOUND, INBOUND CASE WHEN Competitor = 'kay' AND VEHICLE_SIZE= 'Small' THEN MAX(RATE) WHEN COMPETITOR = 'lola' AND VEHICLE SIZE = 'Small'THEN MAX(RATE) WHEN Competitor = 'kay' AND VEHICLE_SIZE= 'Large' THEN MAX(RATE) WHEN COMPETITOR = 'lola' AND VEHICLE SIZE = 'Large'THEN MAX(RATE) ELSE 'RATE' END AS RATE FROM FORMATTED2018AND2019DATA;

Second query:

select Rental_date, outbound, inbound, vehicle_size, max(rate) where competitor='lola' and vehicle_size = 'small' OR 'large' max(Rate)where competitor ='kay' and vehicle_size = 'small' OR 'large' from table2 group by Rental_date, outbound, inbound, vehicle_size,

3
  • You said I need to take the max value of column(rate) of the same vehicle_size and competitor. What about other columns value do you want in your output? Commented Feb 28, 2019 at 3:08
  • Sorry, the rest of the column would be the same as well. Commented Feb 28, 2019 at 3:11
  • Then if you want all only max value of column rate for each group of all others column, you could simply use aggregate function as in @fa06's answer Commented Feb 28, 2019 at 3:16

1 Answer 1

2

Try below -

select  Rental_date, competitor,outbound, inbound, vehicle_size, 
        max(rate) 
        from table2 
        group by 
        Rental_date, competitor,outbound, inbound, vehicle_size
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.