我有3列:( ToDate
,FromDate
,Diff
)。
我想自动为Diff
列添加值,ToDate
和FromDate
之间存在差异,并希望将其保存到表格中。
我可以使用
手动创建临时Diff
列
SELECT ToDate,FromDate, (TO_DAYS(FromDate) - TO_DAYS(ToDate)) AS Diff FROM tbl_name
,
但它不会保存到Diff
列
所以我最终输入了这个:
INSERT INTO tbl_name (Diff) SELECT (TO_DAYS(FromDate) - TO_DAYS(ToDate)) AS Diff FROM tbl_name
我想要这样的事情:
FromDate
2018-05-22
ToDate
2018-05-23
Diff
1