Answer the question
In order to leave comments, you need to log in
How to multiply two values in the table, display the result separately?
In my php script, a dynamic table is created in the sql database using this code:
$query ="CREATE Table IF NOT EXISTS $post_name
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name_prod VARCHAR(200) NOT NULL,
amount double NOT NULL,
summ double NOT NULL,
summ_num double NOT NULL,
data_p VARCHAR(200) NOT NULL,
status VARCHAR(200) NOT NULL
)";
Answer the question
In order to leave comments, you need to log in
You didn't say which database you are talking about.
Some support calculated fields. The value of such a field is not stored in the database, it is calculated in the query process in a "lazy" way imperceptibly, and for SQL it looks like a regular field.
If for some reason a calculated field does not suit you, then you can use a trigger. This less elegant solution is a special stored procedure in the database that runs automatically when a record is changed or in response to some other action and is able to change the value of the fields.
However, I recommend you not to succumb to all these temptations and not to store any code in the database. If you multiply these values directly in SQL queries every time when necessary, then this solution will not be less effective than the previous two. Your formula is not so complicated and quite obvious so as not to add unnecessary entities.
The first solution is searched by the line "%my_db% calculated fields"/
Second: "%my_db% trigger on update"
The third one is not necessary to google. Just keep multiplying.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question