gpt4 book ai didi

mysql - 在更新语句中使用 IF

转载 作者:行者123 更新时间:2023-11-30 23:08:34 24 4
gpt4 key购买 nike

我正在尝试更新特定用户的分数,前提是他添加的文章数量为 >=10

如何添加检查他的 artcAdded 是否为 >=10 的部分?

在伪代码中,这将是;

update tableScores, set score = 'Good' where userId = 1 (if artcAdded for userId = 1 is >= 10) 
// Calcualate and update the score only if his artcAdded is >= 10

我目前这样做 update tableScores set score = 'Good' where userId = 1 and artcAdded >=10; 这可行,但这是正确的方法吗?我应该使用 IF 子句吗?

未处理的表格

"userId"    "artcAdded" "artcApproved"  "artcRejected"  "score"
"1" "10" "7" "3" NULL
"2" "5" "4" "1" NULL
"3" "3" "1" "2" NULL

处理后

"userId"    "artcAdded" "artcApproved"  "artcRejected"  "score"
"1" "10" "7" "3" Good
"2" "5" "4" "1" NULL
"3" "3" "1" "2" NULL

最佳答案

你想要做的是使用一个简单的语句

update tableScores, set score = 'Good' where userId = 1 and artcAdded >= 10

关于mysql - 在更新语句中使用 IF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20781864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com