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
Asked
Active
Viewed 76 times
-1
-
Please provide the structure of the tables concerned. Also provide the SQL you have tried so far. – trincot Nov 01 '15 at 13:54
-
Why was this question closed? I found it rather clear. Sure, it could be improved with details, but hey - we can assume things, can't we? – Lukas Eder Nov 09 '15 at 18:53
-
Yup, but not sure y dey do that – Jayam Koko Nov 13 '15 at 06:33
2 Answers
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