-1

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

APC
  • 144,005
  • 19
  • 170
  • 281
Jayam Koko
  • 49
  • 1
  • 9

2 Answers2

0

test table:

create table orders
(id int
,state varchar2(30)
,city varchar2(30)
,delay int);

test data:

insert into orders(id, state, city, delay)
select rownum as id, owner as state, table_name as city, abs(dbms_random.random) as delay
  from all_tables;

the query:

select * from (
select o.*, row_number() over (order by delay desc) pos from orders o
) where pos = 1
are
  • 2,535
  • 2
  • 22
  • 27
0

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
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509