如何直接在表中插入一笔金额?

时间:2015-09-03 13:13:14

标签: mysql count

INSERT INTO score_1a (red, blue, purple, green, yellow, cyan)  
VALUES (sum(red), sum(blue), sum(purple), sum(green), sum(yellow), sum(cyan) )

这会出现以下错误:

  

无效使用群组功能。

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

我想这会有所帮助

INSERT INTO score_1a (red, blue, purple, green, yellow, cyan)  
select  sum(red), sum(blue), sum(purple), sum(green), sum(yellow), sum(cyan)  
from Score_1a  -- Use other table name if u need from other table

答案 1 :(得分:0)

您必须提供SUM的来源,其中一种方法是使用SELECT语句

INSERT INTO score_1a (red, blue, purple, green, yellow, cyan)  
SELECT
    SUM(red), SUM(blue), SUM(purple), SUM(green), SUM(yellow), SUM(cyan)
FROM
    tbl2

答案 2 :(得分:0)

INSERT INTO `score_1a` (`red`,`blue`, `purple`, `green`,`yellow`, `cyan`)  ( SELECT SUM(red), SUM(blue), SUM(purple), SUM(green), SUM(yellow), SUM(cyan) FROM score_1a );