mysql - 无法使用该表上的条件调用来更新表

标签 mysql

我尝试通过调用该表上的条件来更新我的表,并收到错误。

update grade G
set G.`score` = G.`score` + 5
where G.`snum` IN (select G1.`snum` from grade G1 where G1.`cname` ='Database Systems' And G1.`score` <> 'NULL' AND G1.`score` <= 95));

我不知道为什么它会给我语法错误 因为下面的行给了我 2 个满足条件的 snum。

where G.`snum` IN (select G1.`snum` from grade G1 where G1.`cname` ='Database Systems' And G1.`score` <> 'NULL' AND G1.`score` <= 95));

最佳答案

如果是同一个表,则不需要子查询,只需直接在 where 上添加条件即可子句:

update grade G
   set G.`score` = G.`score` + 5
 where G.`cname` ='Database Systems' 
   And G.`score` <> 'NULL'
   AND G.`score` <= 95;

还有这个And G.score <> 'NULL'这里应该是G.score is not null相反,可能。除非你有 null 作为字符串

关于mysql - 无法使用该表上的条件调用来更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54871831/

相关文章:

c# - 如何在Datatable的DataColumn中只显示日期的月份和年份?

mysql - 使用数组值分割逗号分隔的字符串

mysql - mysql 子字符串反向放置值

mysql - 两种方式连接mysql查询

mysql - 我正在尝试连接两个表,但可以获得预期结果

mysql - 如何锁定 MySQL 中的一行?

用于区分用户的 PHP 全局变量(登录)

php - 在 PHP 中检索到的图像显示不正确

php oop 检查用户是否存在?

php - 替换mysql中的单个字母