G
G
GoodPirojok2020-11-08 14:28:01
PHP
GoodPirojok, 2020-11-08 14:28:01

How to automatically get the result of the 3rd column based on the first two?

Tell me, the table has 3 columns
FinalPrice, Price, Sale

How to make it so that when Sale is empty, FinalPrice is equal to the Price value, but if we add a value to Sale, then FinalPrice would be equal to the Price * Sale formula?

Those. what would he look for in the table in FinalPrice, and not calculate it just before displaying it on the page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-11-08
@GoodPirojok

ALTER TABLE `table`
  ADD COLUMN `FinalPrice` FLOAT 
    AS (IF(`Sale` IS NULL, `Price`, `Price`*`Sale`)) STORED;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question