-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;
4

1 回答 1

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)
于 2012-09-28T08:09:39.583 回答