Tazim Tazim - 7 months ago 11
SQL Question

How can i sum multiple row value in mysql query

I have this results in attached image, I need the total sum of 122 & 455 from "trans_inventory" column.

trans_id trans_items trans_user trans_date trans_comment trans_inventory location_id
8236 1488 1 2016-05-02 02:14:35 Manual Edit of Quantity 10.0000000000 1
8237 1488 1 2016-05-02 02:15:05 RECV 58 122.0000000000 1
8238 1488 1 2016_05-02 02:15:29 RECV 59 455.0000000000 1
8239 1488 1 2016-05-02 02:17:32 NEWP- 506 -55.0000000000 1
8240 1488 1 2016-05-02 02:18:00 NEWP- 507 -121.0000000000 1


How can I get it?

sorry for my bad english. maybe, i can't explain well.

Answer

Try the following query:

SELECT SUM(trans_inventory) FROM (YOUR_QUERY_OF_RESULT_HERE)x 
WHERE trans_comment LIKE "RECV %"

... or when you are using a table:

SELECT SUM(trans_inventory) FROM table_name 
WHERE trans_comment LIKE "RECV %"