'How to auto insert data into database using the values from another table? [duplicate]

I have 2 tables. this is the incomes table

income_id   date_income   total_amount
   1        2022-05-22       14
   2        2022-05-22       15
   3        2022-05-21       20
   4        2022-05-21       25

and this is the total_income table

total_inc_id   income_id  date_income  total total_income_amount
     1             1      2022-05-22     2           29

However I want to count rows with the same date from table1 and store inside table 2 like above automatically whenever i add income. How can i achieve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source