sql - Sum where values of a column matches without number of rows changing -
i trying values of column values of column matches. below sample of data.
dt no_of_records ld_voy_n ld_vsl_m 2017-05-06 04:00:00.000 7 0002w pqo emzmnwp 2017-05-06 20:00:00.000 6 0002w pqo emzmnwp 2017-05-02 04:00:00.000 1 0007e omq ynzmeoyn 2017-05-01 08:00:00.000 2 0016w rmhp sunhpnw 2017-05-01 12:00:00.000 1 0016w rmhp sunhpnw 2017-05-05 12:00:00.000 2 0019n omq wqmsy 2017-05-06 04:00:00.000 12 0019n omq wqmsy
below desired output
dt no_of_records ld_voy_n ld_vsl_m total_no_of_records 2017-05-06 04:00:00.000 7 0002w pqo emzmnwp 13 2017-05-06 20:00:00.000 6 0002w pqo emzmnwp 13 2017-05-02 04:00:00.000 1 0007e omq ynzmeoyn 1 2017-05-01 08:00:00.000 2 0016w rmhp sunhpnw 3 2017-05-01 12:00:00.000 1 0016w rmhp sunhpnw 3 2017-05-05 12:00:00.000 2 0019n omq wqmsy 14 2017-05-06 04:00:00.000 12 0019n omq wqmsy 14
i trying find total_no_of_records column. have ideas?
you seem want window function ld_voy_n
:
select t.*, sum(no_of_records) on (partition ld_voy_n) total_no_of_records t;
Comments
Post a Comment