I have data:
ID DUE AMT
4 2018-03-10 335.75
3 2018-04-10 334.75
1 2018-05-10 333.75
2 2018-06-10 332.75
I need to extract:
Could it be done in single query?
Try keep dense rank:
with tt as (
select 4 id, date '2018-03-10' due, 335.75 amt from dual union all
select 3 id, date '2018-04-10' due, 334.75 amt from dual union all
select 1 id, date '2018-05-10' due, 333.75 amt from dual union all
select 2 id, date '2018-06-10' due, 332.75 amt from dual
)
select min(due) least_due,
min(amt) keep (dense_rank first order by due) amt_for_least_due,
sum(amt) sum_amt
from tt
We can try using analytic functions here:
WITH cte AS (
SELECT ID, DUE, AMOUNT,
SUM(AMOUNT) OVER () AS TOTALAMOUNT,
ROW_NUMBER() OVER (ORDER BY DUE) rn
FROM yourTable
)
SELECT ID, DUE, AMOUNT, TOTALAMOUNT
FROM cte
WHERE rn = 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With