2016-11-28 90 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