05-02-2016 02:58 AM
I want the cumulative sum of rating
so if i use this query
select *,(select sum(rating)as cum from t b where b.no le a.no ) from t a;
I get the desired result .e cumulative sum from top to bottom and if i use
select *,(select sum(rating)as cum from t b where b.no ge a.no ) from t a;
the cmulative sum is showing from bottom to top
please explain the logic
05-02-2016 03:53 AM
In the subquery, for the first record - filter with b.no<=a.no returns the sum of first one record whereas the filter with b.no >= a.no returns the sum of all records.
Likewise, for the second record with 'le' filter returns the sum of first two records whereas with 'ge' filter returns the sum of remaining records except the first one.
Hence you see bottom up cumulative sum for 'ge' condition.
05-02-2016 09:24 AM
so if we say b.no<=a.no then it will be like 1<=1 and then it will check 2<=1 and then 2<=2.That's fine.
But if we say b.no>=a.no then how it is processing?
1>=1 and then 1>=2
can u please explain with taking these example.