Evgeniy Kleban Evgeniy Kleban - 2 months ago 10
SQL Question

Sum specific row values in SQL

I have table with many columns, i interested in column "a", column "b" and column "val". What i need is, to create query, when a is equal to specific int (lets say a=1) and b also equal to specific int (b=1). For every row that match that criteria i want to sum values, that indicated in "val" column. How to create that query?

Answer

You should use a group by clause

select 
    a
    , b
    , sum(val)
from
    [YourTable]
group by
    a
    , b
having
    a = 1
    and b = 1
Comments