将查询结果插入到表中


inserting query result to a table

我这里有

 table_A
| Customer ID | moneyspent |
    001             50
    002             30
    003             20
    003             20
    002             30

我看到一个查询,它从表中得到所有花费的钱的总和

SELECT SUM(moneyspent) FROM table_A

但我想把结果像一样插入表B的"totalwasted"列

 table_B
| Customer ID | totalspent |
   001           50
   002           60
   003           40

请帮忙。感谢

试试这个,我检查过它有效:

INSERT INTO table_B (Customer_ID, totalspent) 
(SELECT Customer_ID, sum(moneyspent) FROM table_A group by Customer_ID)