L
L
LordDolor2021-07-12 16:36:10
MySQL
LordDolor, 2021-07-12 16:36:10

How to create a column that will be the product of two others?

I tried to do this for a long time, it turns out only to withdraw a, I can’t assign

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2021-07-12
@LordDolor

Why add something when you can count?

CREATE TABLE `test`.`test_table` (
  `id` INT NOT NULL,
  `price` INT NULL,
  `count` INT NULL,
  PRIMARY KEY (`id`));

SELECT id, price, count, (price * count) as total FROM test.test_table;

In addition, there is a good rule to create a historical table for the store. Where the order is stored, products and discounts applied at the moment.
And accordingly, you insert there only at the time of placing an order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question