我正在从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 ..我不确定为什么,...有人可以帮我调试此问题吗?
答案 0 :(得分:3)
如果要更新两个不能使用AND
的字段,请用逗号,
分隔每个要更新的字段
update userdailycalorie
set calories_consumed = 205.4
, balanced_diet = true
WHERE user_id = 3;
答案 1 :(得分:2)
您可以在下面尝试-
update userdailycalorie
set calories_consumed= 205.4, balanced_diet =1
WHERE user_id = 3;