hi there I want write inner join on a select without making a view with it like:
select date_,sum(t.weight)-sum(t2.miscalc) as weight from ( select decode(rownum, 1, '20201001',2, '20201005',3, '20201003',4, '20201004', 5,'20201002') as date_, decode(rownum, 1, 9999,2, 8,3, 9998, 4,9999,5, 9997) as weight, decode(rownum, 1, 1299,2, 8,3, 1298, 4,1299,5, 1297) as miscalc from dual connect by level <= 5) t inner join t t2 on t.date_>t2.date_ group by t.date_
my internal select is something like this
and i should subtract sum of all old miscals from weight
Advertisement
Answer
I can do that with with … as clause
with select * from ( select decode(rownum, 1, '20201001',2, '20201005',3, '20201003',4, '20201004', 5,'20201002') as date_, decode(rownum, 1, 9999,2, 8,3, 9998, 4,9999,5, 9997) as weight, decode(rownum, 1, 1299,2, 8,3, 1298, 4,1299,5, 1297) as miscalc from dual connect by level <= 5) as t select date_,sum(t.weight)-sum(t2.miscalc) as weight from t inner join t t2 on t.date = t2.date