SQL在新添加的列中更新多个值?

use*_*812 -1 mysql sql

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

ID   Name  Age  Email(newly added column)
1    Jane  22
2   Melissa 23
3   Andrew  23  
Run Code Online (Sandbox Code Playgroud)

现在我想使用下面的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;
Run Code Online (Sandbox Code Playgroud)

Era*_*nli 5

你需要做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;
Run Code Online (Sandbox Code Playgroud)

表达时使用OR用例:

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)
Run Code Online (Sandbox Code Playgroud)