Yabert Yanuar
Yabert Yanuar

Reputation: 1027

Ask about query in sql server

i have table like this:

 | ID | id_number |   a   |   b  |

 |  1 |     1     |    0  |  215 |
 |  2 |     2     |   28  | 8952 |
 |  3 |     3     |   10  | 2000 |
 |  4 |     1     |    0  |  215 |
 |  5 |     1     |    0  |10000 |
 |  6 |     3     |   10  | 5000 |
 |  7 |     2     |    3  |90933 |

I want to sum a*b where id_number is same, what the query to get all value for every id_number? for example the result is like this :

 | ID | id_number |    result    |

 |  1 |     1     |       0      |
 |  2 |     2     |     523455   |
 |  3 |     3     |     70000    | 

Upvotes: 0

Views: 47

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

This is a simple aggregation query:

select id_number, sum(a*b)
from t
group by id_number

I'm not sure what the first column is for.

Upvotes: 2

Related Questions