mysql互換表中兩列資料

2022-03-04 22:42:41 字數 438 閱讀 1300

mysql互換表中兩列資料

update product set original_price=price,price=original_price;

上面sql語句顯然不可取

因為先執行original_price=price , original_price的值已經更新為price,

然後執行price=original_price,

正確如下

update product as a, product as b set a.original_price=b.price, a.price=b.original_price where a.id=b.id;

a和b個人覺得應該是2個臨時表 最後一定要用where 不用where會出現不對應的情況

mysql互換表中兩列資料

在開發過程中,有時由於業務等需要把乙個表中的兩列資料進行交換。解決方案 使用update命令,這完全得益於mysql sql命令功能的強大支援。中原來資料類似如下 select from product id name original price price 1 雪糕 5.00 3.50 2 鮮花...

mysql互換表中兩列資料方法

小引 大千世界無奇不有,不怕做不到就怕想不到。在mysql軟體開發過程中,有時就需要把乙個表中的兩列資料進行交換。例如,我最近遇到的乙個案例是專案資料準備時客戶把 中兩列資料弄反了 把a列資料輸入到了b列,把b列資料輸入到了a列 真讓人苦笑不得。解決的最好辦法自然是直接修改系統資料庫對應表中資料 如...

mysql互換表中兩列資料方法

create table product id int 10 unsigned not null auto increment comment 產品id name varchar 50 not null comment 產品名稱 original price decimal 5,2 unsigned...