我想在两个现有的列(date1和date2)之间创建一个基于datediff函数的计算列。(以天为单位)
date1和date2是sql DATE类型。
我尝试过但没有成功:
ALTER TABLE my_table ADD lenght AS datediff('dd', date1, date2)谢谢你的帮助。
发布于 2017-08-26 22:53:44
当生成的列在其他列中引用的值发生更改时,该列将自动更新。正确的语法是:
ALTER TABLE my_table ADD length INT GENERATED ALWAYS AS (DATEDIFF('day', date1, date2))发布于 2017-08-26 22:06:08
ALTER TABLE my_table ADD lenght AS int;
UPDATE my_table SET lenght = DateDiff('dd', date1, date2);
-- Don't forget to add a trigger that fires on updated and inserted rows that will keep the value of lenght valid if the date1 or date2 changeshttps://stackoverflow.com/questions/45896144
复制相似问题