2012-09-28 19 views
-3

列出該具有最長的運輸延遲列表對於具有最長的運輸延遲

我嘗試以下,但不能顯示的順序發貨城市和國家的順序發貨城市和國家:

TRENTON   NJ    4 

作爲需要由查詢返回的唯一結果。

select shipcity, shipstate, shipdate-orderdate "Shipping Delay" 
from orders 
having max(shipdate-orderdate) >any (select shipdate-orderdate 
       from orders 
       where shipdate is not null) 
group by shipcity, shipstate, shipdate-orderdate; 

回答

0

假設MySQL的:

select shipcity, shipstate, (shipdate - orderdate) AS "Shipping Delay" 
from orders 
order by "Shipping Delay" desc 
limit 1 

如果你真的堅持子查詢,但當然,上述工程:

select shipcity, shipstate, (shipdate - orderdate) AS Shipping_Delay 
from orders 
where shipdate-orderdate = (SELECT MAX(shipdate-orderdate) FROM orders) 
+0

無恐怕行不通。我想使用子查詢來獲得最長的運輸延遲。 – Anthony

+0

以任何方式計算?我不明白你爲什麼堅持子查詢。 – fancyPants

+0

@安東尼哦,它是計算。感謝你糟糕的格式化,它不是太明顯。更新了我的答案。請再次嘗試第一個查詢。 – fancyPants