D
D
dfhkjhg2020-12-20 18:15:38
PostgreSQL
dfhkjhg, 2020-12-20 18:15:38

How to make a field that will automatically change depending on the data in another table?

There is a table:
With general information about several users
stat:
id | total_amount | total_items

And there is a table with his
inventory items:

id|items_total| amount | stat_id

Is it possible to make the fields stat.total_amount and stat.total_items automatically calculated
So that when a new inventory is added,
total_amount would be updated with the query: select sum(id) from inventory
total items: select count(id) from inventory

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorLaze, 2020-12-20
@dfhkjhg

Create a view and make a request to the view, not to the tables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question