0

I would like to write an sql statement in microsoft access that group items and count their sum

My table is like below :

id : Auto-Increment
Items : String
Quantity : Number

Eg :

id | Items | Quantity
1 | A | 10
2 | B | 5
3 | A | 10
4 | C | 20
5 | C | 20
6 | A | 10
7 | C | 20
8 | B | 5
9 | B | 5

Expected result is

id | Items | Quantity
1 | A | 30
2 | B | 15
3 | C | 60
2
  • 2
    How are you determining the ID for the final result? Those values don't seem to match the sample data.
    – Taryn
    Apr 21 '14 at 15:50
  • 2
    @Mihai the only DBMS that will parse for is MySQL and even there it is illogical and incorrect.
    – Zane
    Apr 21 '14 at 16:01
1

I'm guessing the id column is actually not important in your expected result. In which case, you just need to do a grouping and a summation:

select Items, sum(Quantity) as TotalQty
from MyTable
group by Items

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.