With cte as
(
select A,B, lead(B) over (order by (select 1))C,
Shipments,
lead(Shipments) over (order by (select 1))D,
Shipments + lead(Shipments) over (order by (select 1))Total_Shipments
from shipments
)
Select A,B,Total_Shipments
from cte
where A=C
select LEAST(A,B) as A, GREATEST(A,B) as B, sum(Shipments) as total_shipments from shipment
group by LEAST(A,B) , GREATEST(A,B)
select i.a, i.b,
sum(case when e.a = i.a and e.b = i.a then e.shipments + i.shipments end) as total_shipments
from exp_imp e join exp_imp i
on e.a = i.b and e.b = i.a
and e.shipments < i.shipments
group by i.a, i.b
Nice explanation.please come up with more such questions
Sure. Do watch other videos as well in my channel