How to get all the sum of all the distinct items in MySQL in a single query

  laravel, laravel-query-builder, mysql

Good day devs! I need your opinion on what is the best possible (MySQL or Laravel Query Builder) query on the sample data provided below.

**tbl_transactions**
id, item_code, quantity
1,  0001,      6
2,  0001,      4
3,  0002,      7
4,  0002,      3

How do I get all the sum of all the distinct items? e.g. 0001 equals 10 and 0002 equals 10

Any idea/opinion is highly appreciated! Thanks 🙂

Source: Laravel

Leave a Reply