I am retrieving the SUM of some data from a query. The SUM can have both negative and positive values. I want to insert the positive values to one table and the negative values to another table.
The result set for the select query is like below
total | userid
-----------------------
4750.00 | 11
1339.00 | 3607
-681.81 | 3600
I was planning to insert the details from the select query directly to the table, INSERT into table (amount,user) SELECT SUM(..) AS total,userid FROM... . But I was not able to figure out how to do it in a single query.
I am using PostgreSQL 8.4.17
if/elsestatement in between theINSERTandSELECTquery