Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL是否更新新添加列中的多个值?_Mysql_Sql - Fatal编程技术网

Mysql SQL是否更新新添加列中的多个值?

Mysql SQL是否更新新添加列中的多个值?,mysql,sql,Mysql,Sql,我在MySQl中有一个名为friends的数据库,假设friends表中有三行 ID Name Age Email(newly added column) 1 Jane 22 2 Melissa 23 3 Andrew 23 现在我想使用下面的SQL语法向数据库中的每个人添加电子邮件,但它不起作用。我哪里出错了 Update friends set email= 'jane@abc.com' where id = 1, set email= 'Melissa@ab

我在MySQl中有一个名为friends的数据库,假设friends表中有三行

ID   Name  Age  Email(newly added column)
1    Jane  22
2   Melissa 23
3   Andrew  23  
现在我想使用下面的SQL语法向数据库中的每个人添加电子邮件,但它不起作用。我哪里出错了

Update friends
set email= 'jane@abc.com' where id = 1,
set email= 'Melissa@abc.com' where id = 2,
set email= 'Andrew@abc.com' where id = 3;

您需要执行3种不同的查询,如:

Update friends set email= 'jane@abc.com' where id = 1;
Update friends set email= 'Melissa@abc.com' where id = 2;
Update friends set email= 'Andrew@abc.com' where id = 3;
或在表达式出现以下情况时使用用例:

Update friends set email= (case when id=1 then 'jane@abc.com'
                                when id=2 then 'melissa@abc.com'
                                when id=3 then 'andrew@abc.com' end)

你的陈述是正确的。只需删除逗号并分别运行这些语句

Update friends set email= 'jane@abc.com' where id = 1;
Update friends set email= 'Melissa@abc.com' where id = 2;
Update friends set email= 'Andrew@abc.com' where id = 3;

既然您使用的是MySQL,为什么要在问题中添加Oracle和Microsoft SQL Server标记?答案可能取决于您使用的数据库管理系统。啊,我明白了。非常感谢Eray的澄清,您的解决方案非常有效!当缺少结束关键字时,似乎是
情况乐于帮助用户71812。如果您通过单击左侧的勾号@user71812选择正确答案,将不胜感激