Hello everyone, when working with a view in mysql, I encountered the following situation: I created a table:

CREATE TABLE IF NOT EXISTS schema.table( row_id INT(255) NOT NULL AUTO_INCREMENT PRIMARY KEY, val1 DOUBLE, val2 DOUBLE, val3 DOUBLE); 

In val1 and val2 mediated arbitrary data, val3 filled in only one line:

 INSERT INTO schema.table (va1, val2) VALUES (1, 2); INSERT INTO schema.table (va1, val2) VALUES (3, 4); INSERT INTO schema.table (va1, val2) VALUES (5, 6); 

And created a view based on this table:

 CREATE OR REPLACE VIEW test_VIEW AS select t1.row_id as row_id, if (t1.val3 is null, SUM(t1.val1 + t1.val2) OVER(), t1.val3) AS val3 from test t1 

The problem itself - how to save the calculated view value from val3 to a table in val3?

  • view from the table is almost the same, so that .stackoverflow.com/q/597149/194569 - Mike
  • In the table, this could be implemented with an insert / update trigger, but how to trigger an update from your example when calculating a view? - mysqllearn 4:04
  • And why do this with every view calculation? After all, the view is created only in order not to write the same code in several places to receive something. And what is something that is easy to calculate and that do not need to be stored at all. This is me to the fact that there may be a lot of samples from the view and on each of them something to update the database is clearly not correct. It seems you are trying to solve some other problem for which no view is needed at all - Mike
  • The task is that there is a table and the conditional DB user needs to see some data that is the product / sum / td of values ​​from its columns. When searching for a solution, the most appropriate option was to create a view. But I also consider not very correct to store such data in a virtual form. - mysqllearn 4:41
  • it is not clear why the same amount is needed in all rows of data. This is more like the string "Total" in some kind of report, which is usually shown once to the user somewhere at the end. And to store in each data line the total amount of all the lines is an even stranger solution. If something in the database has to be stored more than 1 time, then with the structure of such a database there is exactly something wrong. If the receipt of the amount is slow, then only in this case it should be stored and the storage should be a separate table, where this amount will be in a single copy and be triggered - Mike

0