匹配的行数:1已更改:0警告:0 mysql更新未发生

alen0pnh  于 2021-06-15  发布在  Mysql
关注(0)|答案(2)|浏览(605)

我正在从mysql命令行更新一个表。。更新未发生。。
表格说明如下:

mysql> describe userdailycalorie;
+-------------------+----------+------+-----+---------+-------+
| Field             | Type     | Null | Key | Default | Extra |
+-------------------+----------+------+-----+---------+-------+
| id                | int(11)  | NO   | PRI | NULL    |       |
| balanced_diet     | bit(1)   | YES  |     | NULL    |       |
| calories_consumed | double   | YES  |     | NULL    |       |
| date              | datetime | YES  |     | NULL    |       |
| user_id           | int(11)  | YES  | MUL | NULL    |       |
+-------------------+----------+------+-----+---------+-------+
5 rows in set (0.13 sec)

相应的表格内容如下:

mysql> select * from userdailycalorie;
+----+---------------+-------------------+---------------------+---------+
| id | balanced_diet | calories_consumed | date                | user_id |
+----+---------------+-------------------+---------------------+---------+
| 16 |               |                 0 | 2018-02-02 00:00:00 |       3 |
+----+---------------+-------------------+---------------------+---------+
1 row in set (0.00 sec)

相应的update语句如下:

mysql> update userdailycalorie  set calories_consumed= 205.4  and balanced_diet =true WHERE user_id = 3;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

匹配的行数为1,表示它选择了行。。更新未按更改进行:0。。我不知道为什么,。。。有人能帮我调试这个问题吗?

ukxgm1gy

ukxgm1gy1#

如果你想更新两个字段不能使用 AND ,用coma分隔要更新的每个字段 , ```
update userdailycalorie
set calories_consumed = 205.4
, balanced_diet = true
WHERE user_id = 3;

snvhrwxg

snvhrwxg2#

你可以在下面试试-

update userdailycalorie  
set calories_consumed= 205.4, balanced_diet =1
WHERE user_id = 3;

相关问题