我有4张赌桌,位置,时间和检查室。
Car< - N:m - >时间 检查室是关系表。
我只想要日期(从时间),位置名称和具有最高运行时间的car_name。
任何人都可以提示,如何解决问题?
答案 0 :(得分:0)
尝试使用此查询:
select Time.Time_date, Location.Location_name, Car.Car_name
from Time
inner join Checkroom on Time.Time_ID = Checkroom.Time_ID
inner join Location on Checkroom.Location_ID = Location.Location_ID
inner join Car on Checkroom.Car_ID = Car.Car_ID
where Time.Time_runtime = (select MAX(Time_runtime) from Time)
答案 1 :(得分:0)
在Oracle案例中,JOIN
表格ORDER BY Time_runtime DESC
,使用FETCH FIRST
仅获得一行 - Time_runtime最高的一行。
select Time.Time_date, Location.Location_name, Car.Car_name
from Time
inner join Checkroom on Time.Time_ID = Checkroom.Time_ID
inner join Location on Checkroom.Location_ID = Location.Location_ID
inner join Car on Checkroom.Car_ID = Car.Car_ID
order by Time.Time_runtime DESC
FETCH FIRST 1 ROWS ONLY
FETCH FIRST
仅适用于较新的Oracle版本。