2012-09-28 5 views
-3

목록 목록 가장 긴 운송 지연

내가 다음 만 표시 할 수없는 시도 긴 운송 지연 한 주문에 대한 운송 도시와 국가했던 주문의 운송 도시와 국가 :

TRENTON   NJ    4 

은 쿼리에서 반환해야하는 유일한 결과입니다. MySQL의 가정

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

:

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

I이 작동하지 않습니다 두려워 아니. 없다 가장 긴 배송 지연을 얻기 위해 하위 쿼리를 사용한다고 가정합니다. – Anthony

+0

그것은 어떤 식 으로든 계산됩니까? 나는 왜 당신이 서브 쿼리를 고집하는지 보지 못한다. – fancyPants

+0

@Anthony 오, 계산됩니다. 형편없는 서식 덕분에 너무 분명하지 않았습니다. 내 대답이 업데이트되었습니다. 첫 번째 쿼리를 다시 시도하십시오. – fancyPants