I am trying to add a computeed column.
alter table datatest add column amount2 double as (amount*rate)
but I got error while executing this
I am trying to add a computeed column.
alter table datatest add column amount2 double as (amount*rate)
but I got error while executing this
MySQL doesn't support computed columns prior to MySQL 5.7. The more recent versions do now support computed columns.
You can use a view instead:
create view v_datatest as
select t.*, (amount * rate) as amount2
from datatest;
Notes:
cast()
/convert()
to convert to a particular type).decimal
/numeric
instead.