[英]SQL Oracle return only max(value) of column value
My data looks like this. 我的数据看起来像这样。
The output I am looking to see is: 我希望看到的输出是:
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.
我需要取相同vehicle_size和竞争对手的列(速率)的最大值。 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,
Try below - 试试以下 -
select Rental_date, competitor,outbound, inbound, vehicle_size,
max(rate)
from table2
group by
Rental_date, competitor,outbound, inbound, vehicle_size
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.