Reputation: 35
I have the below data in one table, what I am trying to do is to calculate how many times each test occurs and the total amount for each test. I would like the end result to look like this:
code = A Quantity = 3 Amount = $15
code = B Quantity = 3 Amount = $21 and so on.
Any help would be appreciated
A test 1 $5
A test 1 $5
A test 1 $5
B test1 1 $7
B test1 1 $7
B test1 1 $7
C test2 1 $12
C test2 1 $12
C test2 1 $12
Upvotes: 1
Views: 35
Reputation: 133360
You can use aggregate function sum and group by
select code, sum(quantity), sum(aAmount)
from mytable
group by code
Upvotes: 1