更新同一列中的多个值
Updating Multiple Values in the Same Column
我有一个名为 Movie_Stars 的数据 table。我想更新多个值,但它们都在同一列中。这是我拥有的:
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';
但这会产生错误 "invalid user.table.column, table.column, or column specification"。那么什么是右栏规范呢?
使用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')
我有一个名为 Movie_Stars 的数据 table。我想更新多个值,但它们都在同一列中。这是我拥有的:
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';
但这会产生错误 "invalid user.table.column, table.column, or column specification"。那么什么是右栏规范呢?
使用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')