sql - Sum column in last row -
i need sum of column value in column total grouped year, month , day, sum must in "last" row of group
year month day value total 2017 5 10 10 0 2017 5 21 5 0 2017 5 28 3 18 2017 6 15 8 8 2017 7 14 9 0 2017 7 18 2 11
how can ?
you seem want total on last record each month. can using ansi standard window functions:
select t.*, (case when row_number() on (partition year, month order day desc) = 1 sum(value) on (partition year, month) else 0 end) total t;
Comments
Post a Comment