netezza - Sum of Rows - SQL query -
i need develop sql query following:
column column b row1 2861682 sum(row1 row5) row2 2522226 sum(row2 row5) row3 2285983 sum(row3 row5) row4 2096046 sum(row4 row5) row5 1935355 sum(row5)
this data have in table column.
now need calculate
sum(row1 row5) sum(row2 row5) sum(row3 row5) sum(row4 row5) sum(row5)
thanks
the standard sql form uses correlated subquery:
select t.*, (select sum(b) t t2 t2.a >= t.a ) thesum t;
some databases support window/analytic functions allow cumulative sums.
edit:
netezza 1 of databases support cumulative sums using window functions (thanks postgres heritage, imagine). can express as:
select t.*, sum(b) on (order desc) thesum t
edit ii:
i don't have netezza database test on, have rowid
column. might able use this, although cannot find documentation guarantees being monotonically increasing. in fact, i'm pretty sure parallel load, rowid not monotically assigned.
the query like:
select t.*, sum(b) on (order rowid desc) thesum t
Comments
Post a Comment