MySQL 如果那么设置
我有一个带有
*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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用:
...或者,使用 DATE_SUB:
Use:
...or, using DATE_SUB:
我是这样做的。
Here is how i did it.
将额外条件放入 WHERE 子句中:
Put the extra condition in the WHERE clause: