如何在现有列中添加值? (MYSQL)

时间:2018-05-21 03:08:01

标签: mysqli insert field multiple-columns insert-update

我有3列:( ToDateFromDateDiff)。

我想自动为Diff列添加值,ToDateFromDate之间存在差异,并希望将其保存到表格中。

我可以使用

手动创建临时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

0 个答案:

没有答案