如何在mysql查询中求和多行值

时间:2016-05-01 21:34:57

标签: mysql

我在附加图像中得到这个结果,我需要122和&的总和。 455来自“trans_inventory”专栏。

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

我怎样才能得到它?

抱歉我的英语不好。也许,我无法解释清楚。

2 个答案:

答案 0 :(得分:0)

尝试以下查询:

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

......或当您使用桌子时:

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

答案 1 :(得分:0)

使用SUM函数:

SELECT SUM("trans_inventory") FROM table_name WHERE trans_id = 8237 OR trans_id = 8238;