MySQL总和选中的行

时间:2014-07-17 10:06:52

标签: mysql

我想总结多行选择ID我的代码是

SELECT sum(yellow) AS yellow,
       sum(orange) AS orange,
       sum(red) AS red,
       sum(blue) AS blue,
       sum(green) AS green,
       sum(purple) AS purple
FROM main
WHERE ID IN ('180 , 182')

但是获得第一个ID只是不加两者。

1 个答案:

答案 0 :(得分:0)

将您的查询修改为

SELECT sum(yellow) AS yellow,
       sum(orange) AS orange,
       sum(red) AS red,
       sum(blue) AS blue,
       sum(green) AS green,
       sum(purple) AS purple
FROM main
WHERE ID IN ('180' , '182');
                 ^   ^
                  Place single quotes here

More about MySQL IN clause