0

I am new to MySQL, currently I've been trying to create a column in a table that contains the total of payment an individual has to pay. For references, the first picture is how I want the tables to look like (in the big picture). tables What i want is that in the column of total_to_pay, it automatically sums up the value of price from Mobile_Subscription, value of price from TV_Subscription and value of payment_from_past from History. So I want it to basically look something like this: values I want to know if such thing is possible and if not how can i make something similar?

I searched on Google this problem but all I could find was how to sum all values from 2 different columns, when what I wanted is to sum 2 (or 3) specific values from 2 different column from 2 different tables.

  • You'll have to write a trigger. [This link](https://stackoverflow.com/questions/20157972/calculate-column-value-from-another-column-in-another-table) might be useful – May Rest in Peace Oct 31 '22 at 09:58
  • Not the approach I would take, Unless the data is substantially different I would have 1 subscription table with a column indicating tv or mobile, and transaction table to store payments received and I would not hold a total_of_pay at all since it can be derived. – P.Salmon Oct 31 '22 at 10:04

0 Answers0