Creating Autosumming Fields

Assuming PostgreSQL as a database.

You have 2 options how to make it “right”:

  • Views in the DB (potentially materialised)
  • If you are on Postgres 12+ then you can use generated fields

Both will make your application much clearer and, at least logically, normalise your data.