用select the same table[mysql]更新

u5i3ibmn  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(364)

你们能帮我用同一张表更新这个表吗?我的table:

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 |         |

我可以选择表来计算日差

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    |
rekjcdws

rekjcdws1#

好吧,你可以这样做

update table_name set day_diff = DATEDIFF(pass_date , CURDATE());

相关问题