0
| id  |  price  |   quantity  |  total  |
|  1  |   5     |      5      |    25   |

I want to create a total = price * quantity column. What I have to do??

Strawberry
  • 33,338
  • 13
  • 38
  • 57

1 Answers1

0

You could use generated column:

ALTER TABLE tab
ADD COLUMN total INT GENERATED ALWAYS AS (price*quantity) STORED;
                 -- INT or any appropriate data type

DBFiddle Demo

Lukasz Szozda
  • 139,860
  • 19
  • 198
  • 228