2016-11-28 89 views
1

我有一个名为Movie_Stars的数据表。我想更新多个值,但它们都在同一列中。以下是我的:更新同一列中的多个值

update movie_stars 
set movie_category = 'Family' 
where movie_category = 'Drama' 
and set movie_category = 'Children' 
where movie_category = 'Cartoon' 
and set movie_category = 'Teen' 
where movie_category = 'Action'; 

但是,这会产生错误“无效的user.table.column,table.column或列规范”。那么什么是正确的色谱柱规格?

回答

1

使用CASE表达:

update movie_stars 
set movie_category = case when movie_category = 'Drama' 
          then 'Family' 
          when movie_category = 'Cartoon' 
          then 'Children' 
          when movie_category = 'Action' 
          then 'Teen' 
        end 
where movie_category in ('Drama', 'Cartoon', 'Action') 
+0

遗憾,但是当我运行你的代码,它说:“无效的关系运算符”。 – Tim

+0

@Tim对不起,我有一个错字,请再试一次。顺便说一句,名字很好! –

+0

是的!有效!谢谢蒂姆! – Tim