在SQL查询中排序

时间:2011-11-30 13:05:44

标签: sql tab-ordering

So here are my two tables

我需要选择不同的vehicle.model行并按rate.day值对它们进行排序。 对查询的帮助不大?

感谢您考虑我的问题。

3 个答案:

答案 0 :(得分:2)

select distinct model, day_rate from vehicle
  inner join rate on vehicle.vehicle_type = rate.vehicle_type
  order by day_rate

现在。去做作业......

答案 1 :(得分:0)

select distinct v.model
from vehicle v
inner join rate r
on v.vehicle_type = r.vehicle_type
order by r.day_rate

答案 2 :(得分:0)

SELECT 
    v.model
FROM 
    vehicle v
  JOIN
    rate r
      ON r.vehicle_type = v.vehicle_type
ORDER BY r.day_rate 

或更好:

SELECT  
    model
FROM 
    vehicle v
GROUP BY 
    model
ORDER BY 
    ( SELECT 
          r.day_rate
      FROM 
          rate r
      WHERE 
          r.vehicle_type = MIN(v.vehicle_type) 
    )