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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -