"where" 或附近的 Postgresql 语法错误

Postgresql Syntax error at or near "where"

我遇到错误

syntax error at or near "where" LINE 5: where zip in (select zipcode from zips where city = 'Sacra

当我尝试 运行 这段代码时。

update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100)))
where zip in (select zipcode from zips where city = 'Sacramento');

有人看到任何容易修复的错误吗?还是我想出了一些垃圾代码?

update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100)))
where zip in (select zipcode from zips where city = 'Sacramento')

删除;再试一次

SQL CASE expression 需要以 END 关键字结尾。

where 子句

之前添加一个 end 关键字
update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100))) END
where zip in (select zipcode from zips where city = 'Sacramento');

根据@a_horse_with_no_name的评论

update listings 
set price = (price * (((100+(select price_change from zips where zips.zipcode=listings.zip))/100))) 
where zip in (select zipcode from zips where city = 'Sacramento') and listings.price IS NOT NULL