PostgreSQL (PgAdmin 4). I have two tables. I add data to the first table time by time using insert for all columns.
Table1:
CREATE TABLE purchases (
id INTEGER,
name VARCHAR,
qty INTEGER,
date TIMESTAMP,
price NUMERIC,
about VARCHAR )
Table2:
CREATE TABLE result (
id INTEGER,
name VARCHAR,
qty INTEGER,
date TIMESTAMP,
profit NUMERIC,
sold NUMERIC )
- First table is as list (history) of purchases and many rows would be added there. I want my second table to check if there in the first table added any new (not existing in Table2) names and add new row to my Table2 with such name (name is a field in my tables)
- If i put in my first table two rows:
a) name - cheese, qty - 20
b) name - cheese, qty - 20
Then can i do thing that in my empty Table2 must appear the row: name - cheese, qty - 40 (sum of qtyS from my Table1) In the first table won't be only cheese but many other product. I just want to add only new rows to my second table and if there appears a new row in Table1 with existing name in Table2 with any quantity - then i update certain row in Table2 with new total sum of product.
I am starting my way to this and I would be souly gratefull to those who help me))
Please, provide your answers wide & fully if u are able to do it!