add values from one table and put the result in another

2

I have a table called players and I need to add the values of the points column but only those that have the same account_id and after putting the result in another table called accounts just in which it has the indicated id. The result would be this:

Table players:

account_id    |pontos      
1             |50  
1             |100               
2             |25              
2             |20     

Accounts table:

id            |pontos      
1             |150
2             |45
    
asked by anonymous 26.08.2015 / 19:32

1 answer

2

try this:

INSERT INTO accounts values (select account_id as id, SUM(pontos) from players group by account_id);
    
26.08.2015 / 19:35