In fact, you do not need to use the case :
update royalties set royalty = royalty * 1.2 where royalty >= 0.16; update royalties set royalty = royalty * 1.2 where royalty >= 0.11 and royalty < 0.16; update royalties set royalty = royalty * 1.1 where royalty < 0.11;
(with transactional control, if you need atomicity). You could combine the first two if they have the same factor as your question.
It works by ensuring that you first execute higher values ββand limit which lines affect the where clause.
If you think you need to use the case :
update royalties set royalty = case when royalty >= 0.16 then royalty * 1.2 case when royalty >= 0.11 and royalty < 0.16 then royalty * 1.2 case when royalty < 0.11 then royalty * 1.1 end;
To just change what you pull from the table (instead of changing the table itself) and compare it with the current one:
select title_id, lorange, hirange, royalty, case when royalty >= 0.16 then royalty * 1.2 case when royalty >= 0.11 and royalty < 0.16 then royalty * 1.2 case when royalty < 0.11 then royalty * 1.1 end as new_royalty from royalties;
paxdiablo
source share