1

我正在尝试row 3(id=8)在我的表中更新

使用以下查询:

UPDATE player_ban 
   SET until = Now(), 
       unbanned_by = "MrSnare", 
       unbanned_reason = "test", 
       unbanned_date = Now() 
 WHERE name = "MCYasman" 
     & unbanned_by = NULL 
     & until > NOW();

查询正在运行,但没有更新任何行。

出了什么问题?

4

3 回答 3

8

我会更改您的查询以使用AND而不是&and unbanned_by IS NULL。所以查询将是:

UPDATE player_ban 
SET until = Now(), 
    unbanned_by = "MrSnare", 
    unbanned_reason = "test", 
    unbanned_date = Now() 
WHERE name = "MCYasman" 
  AND unbanned_by IS NULL 
  AND until > now();

一个值永远不会是= null,你必须使用IS NULL

于 2013-01-02T22:56:00.970 回答
3

不使用&AND改为使用

 WHERE name = "MCYasman" AND unbanned_by IS NULL AND until > now();
于 2013-01-02T22:56:26.050 回答
0

您需要更改 unbanned_by 检查以使用“is null”而不是“= NULL”。像这样。

UPDATE player_ban SET until = Now(), unbanned_by = "MrSnare", unbanned_reason = "test", unbanned_date = Now() WHERE name = "MCYasman" & unbanned_by is NULL & until > now();

NULL 在 SQL 中不等于自身。

> select null = null, null is null, null is not null;
+-------------+--------------+------------------+
| null = null | null is null | null is not null |
+-------------+--------------+------------------+
|        NULL |            1 |                0 |
+-------------+--------------+------------------+
1 row in set (0.00 sec)
于 2013-01-02T22:57:15.177 回答