MySQL 如果那么设置

发布于 2024-09-25 21:33:55 字数 1029 浏览 3 评论 0原文

我有一个带有

*PwdSettings 的表,其值为 -50(即 50 天)

*PwdDate(这是上次更新的日期)

*ExpDate (这是 0 或 1,如果密码是旧的,我需要将其设置为 1)

我正在尝试编写一个查询来表示“IF PwdDate is < PwdSettings then SET ExpDate = 1”

这是我所拥有的到目前为止尝试过,一切都会引发错误。

UPDATE wp_users SET ExpDate = 1 WHEN PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) WHERE user_email='[email protected]'

UPDATE wp_users SET ExpDate = 1 WHERE user_email='[email protected]' IF(PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY))

IF PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) WHERE user_email='[email protected]' THEN SET ExpDate = 1

I have a table with

*PwdSettings that has a value of -50 (which is say 50 days)

*PwdDate (which is the date last updated)

*ExpDate (which is 0 or 1, if Password is old i need it set to 1)

I'm trying to write a query to say "IF PwdDate is < PwdSettings Then SET ExpDate = 1"

Here is what I have tried so far, everything throws an error.

UPDATE wp_users SET ExpDate = 1 WHEN PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) WHERE user_email='[email protected]'

UPDATE wp_users SET ExpDate = 1 WHERE user_email='[email protected]' IF(PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY))

IF PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) WHERE user_email='[email protected]' THEN SET ExpDate = 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽清梦 2024-10-02 21:33:55

使用:

UPDATE wp_users 
   SET ExpDate = 1 
 WHERE PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) 

...或者,使用 DATE_SUB:

UPDATE wp_users 
   SET ExpDate = 1 
 WHERE PwdDate < DATE_SUB(CURDATE(), INTERVAL 50 DAY) 

Use:

UPDATE wp_users 
   SET ExpDate = 1 
 WHERE PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) 

...or, using DATE_SUB:

UPDATE wp_users 
   SET ExpDate = 1 
 WHERE PwdDate < DATE_SUB(CURDATE(), INTERVAL 50 DAY) 
半衾梦 2024-10-02 21:33:55

我是这样做的。

UPDATE wp_users 
SET ExpDate = IF(PwdDate <= DATE_ADD(CURDATE(), INTERVAL PwdSettings DAY), 1, 0)
WHERE user_email='[email protected]'

Here is how i did it.

UPDATE wp_users 
SET ExpDate = IF(PwdDate <= DATE_ADD(CURDATE(), INTERVAL PwdSettings DAY), 1, 0)
WHERE user_email='[email protected]'
你另情深 2024-10-02 21:33:55

将额外条件放入 WHERE 子句中:

UPDATE wp_users
SET ExpDate = 1
WHERE user_email='[email protected]'
AND PwdDate < CURDATE() - INTERVAL 50 DAY

Put the extra condition in the WHERE clause:

UPDATE wp_users
SET ExpDate = 1
WHERE user_email='[email protected]'
AND PwdDate < CURDATE() - INTERVAL 50 DAY
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文