2014-01-23 42 views
0

我一直在使用笛卡爾prouct如何利用改寫這個SQL腳本JOINS

SELECT name 
FROM Station, Sale, Fuel 
WHERE (Station.id_station=Sale.id_station) AND (Sale.id_fuel=Fuel.id_fuel) 
     AND MAX(Fuel.volume) 

我想知道我怎樣才能讓它在使用連接使這個SQL腳本。基本上,它選擇有最大油箱的油站的名稱。

回答

3

你可以做那樣的事情。

select top 1 name 
from station st 
inner join sale sa on sa.id_station = st.id_station 
inner join fuel f on f.id_fuel = sa.id_fuel 
order by f.volume desc; 
0
SELECT name 
    FROM Station 
    INNER JOIN Sale ON Station.id_station=Sale.id_station 
    INNER JOIN Fuel ON Sale.id_fuel=Fuel.id_fuel 
    WHERE MAX(Fuel.volume)= ? 

你還沒說你最大(Fuel.colume)想要的東西,這就是爲什麼?在那兒。