where xx in(变量)问题,为什么下边的语句只能更新第一条数据?begin;
select @ids:=GROUP_CONCAT(id) from tag where id in(1,2);
update tag set data_count=data_count-1 where id in(@ids) and data_count!=0;
commit;上边的语句为什么只能成功更新id为1的数据?但如果我直接把上边的换成:
update tag set data_count=data_count-1 where id in(1,2) and data_count!=0;
下边这样的语句又不能通过
update tag set data_count=data_count-1 where id in(select id from tag where id in(1,2);) and data_count!=0;
select @ids:=GROUP_CONCAT(id) from tag where id in(1,2);
update tag set data_count=data_count-1 where id in(@ids) and data_count!=0;
commit;上边的语句为什么只能成功更新id为1的数据?但如果我直接把上边的换成:
update tag set data_count=data_count-1 where id in(1,2) and data_count!=0;
下边这样的语句又不能通过
update tag set data_count=data_count-1 where id in(select id from tag where id in(1,2);) and data_count!=0;
还是用联合更新好update tag A,tag B
set A.data_count=data_count-1
where A.id=B.id and B.id in (1,2);
我会这样用是因为下边的语法可以成功
select @ids:=GROUP_CONCAT(id) from tag where tag_md5 in('b397dc8b27cc08a0');
update data_2_tag set tag_ids=@ids where data_id=1;
or
SET @asql=CONCAT('update tag set data_count=data_count-1 where id in(\'',
@ids,'\')');
prepare stml from @asql;
execute stml