2012-09-28 20 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