开发者

up table set number2 = number where number != "" and set number, number2 = $number where number = "";;

开发者 https://www.devze.com 2023-01-08 10:46 出处:网络
is this possible? update table set number2 = number where number != \"\" and set number, number2 = $number where number=\"\";

is this possible?

update table set number2 = number where number != "" and set number, number2 = $number where number="";

or do i need to do

update table set number2 = number where number != "";
update table set number = $number开发者_开发百科, number2 = number where number = "";


I would just do them as two "separate" statements and not worry about trying to find a clever solution (which is rarely clever IMNSHO).

You'll see I quoted the word "separate" above since any decent DBMS will provide transactional support which will make the two of those statements into one, in terms of atomicity (the A in ACID).

In other words, something like:

start transaction;
update table set number2 = number where number != "";
update table set number = $number, number2 = number where number = "";
commit transaction;

This will almost invariably be faster (assuming number is indexed) than a clever solution using per-row functions like CASE, IF and so on, since two very fast passes is better than one slow pass :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号