如果想实现这个修改update barcode set colorid = 'B' where goodis between 100 and 110就行了
如果是不能用一个简单的where查询完成
需要把查询结果指定一个新的表名
mysql是不支持同一个sql语句中update或delete同一个表的select结果的
语句如下:
update barcode
set colorid='B'
where colorid in
(select colorid from (select * from barcode where goodis between 100 and 110) as a);
update barcode set colorid = 'B' where goodis between 100 and 110
结果集是个内存中的临时表,更新了有意义吗。
update colorid='B' where goodis between 100 and 110
可以使用merge很简单的实现,语法如下:
MERGE INTO table_name alias1
USING (table|view|sub_query) alias2
ON (join condition)
WHEN MATCHED THEN
UPDATE table_name
SET col1 = col_val1,
col2 = col2_val
WHEN NOT MATCHED THEN
INSERT (column_list) VALUES (column_values);