0

I am trying to get the sum of amount from purchases and insert it into the table total_expenses. I don't really understand how to add the values of aggregate functions into other tables as new tuples. Could someone help me on this?

INSERT INTO total_expenses VALUES (Select sum(amount) from purchases);

This procedure gives me "ERROR: syntax error at or near "select""

1 Answer 1

1

Don't use the VALUES keyword if the source of your INSERT statement is a SELECT statement. You should also specify your target columns:

INSERT INTO total_expenses (amount) 
select sum(amount) 
from purchases;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.