我想要总和所有具有相同型号的QTY

时间:2018-03-08 23:03:07

标签: php mysql sql

enter image description here

SL是主键。 表名 - > IMPO 我想总结所有具有相同型号的QTY。(这里因为INDO666而增加40 + 35)

我试过了:

SELECT i.Model_num, i.QTY 
FROM impo AS i 
    JOIN (SELECT Model_num, SUM(QTY) AS t_qty 
            FROM impo 
            GROUP BY Model_num ) 
    AS s ON i.Model_num = s.Model_num

1 个答案:

答案 0 :(得分:2)

我不明白为什么你有额外的join。子查询似乎做你想要的:

SELECT Model_num, SUM(QTY) AS t_qty 
FROM impo 
GROUP BY Model_num ;