sql server - Query to loop through a column and calculate totals for each unique record -


this might better done script, hoping can done query.

i have table called ledger. looks (simplified):

patid  amount   100    2500 100    1700 100    700 110    500 110    -75 120    350 

can query @ table , return single line each patid correct total based on amount field?

in case, want report:

patid  amount 100     4900 110     425 120     350 

thanks!

you can try using simple group by sum this,

 select        patid,       sum(amount) amount         yourtable  group        patid 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -