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,750
  • 13
  • 40
  • 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
  • 162,964
  • 23
  • 234
  • 275