Search code examples
sqloracle-databaseoracle11gtop-n

Oracle sql fiding shipping delay


can i know how i could write the sql statement in listing the shipping city and state for the order that has the longest shipping delay. I not sure need use the function Max in where


Solution

  • I'm assuming your data structure is flat, as in:

    CREATE TABLE orders (
      ...
      shipping_city VARCHAR2(100),
      shipping_state VARCHAR2(100),
      shipping_delay NUMBER(7),
      ...
    );
    

    You can now write:

    SELECT
      MAX(shipping_city)  KEEP (DENSE_RANK LAST ORDER BY shipping_delay),
      MAX(shipping_state) KEEP (DENSE_RANK LAST ORDER BY shipping_delay)
    FROM
      orders