id | pass_date | daydiff |
1 | 2018-04-20 14:49:24 | |
2 | 2018-04-21 14:49:24 | |
3 | 2018-04-20 14:49:24 | |
我可以选择表来计算daydiff
SELECT id, DATEDIFF(pass_date , CURDATE()) as daydiff FROM users
结果:
id | daydiff |
1 | 3 |
2 | 2 |
3 | 3 |
我想要做的是更新daydiff列,如下所示:
id | pass_date | daydiff |
1 | 2018-04-20 14:49:24 | 3 |
2 | 2018-04-21 14:49:24 | 2 |
3 | 2018-04-20 14:49:24 | 3 |
答案 0 :(得分:1)
您可以执行以下操作
update table_name set day_diff = DATEDIFF(pass_date , CURDATE());