语句如下 select count(id) t_count from cet6 where word='a';
if t_count> 0 then
update set cet68=2,total=total+2 where word='a';
else
insert into cet6(word,total,cet68) values('a',2,2);
end;
if t_count> 0 then
update set cet68=2,total=total+2 where word='a';
else
insert into cet6(word,total,cet68) values('a',2,2);
end;
if t_count> 0 then
update cet6 set cet68=2,total=total+2 where word='a';
else
insert into cet6(word,total,cet68) values('a',2,2);
end;
这些语句一定要在存储过程或者存储函数里面做才可以!declare t_count int unsigned default 0;
select count(id) into t_count from cet6 where word='a';
if t_count> 0 then
update cet6 set cet68=2,total=total+2 where word='a';
else
insert into cet6(word,total,cet68) values('a',2,2);
end if; 仔细看手册!熟悉语法!
select count(id) into @t_count from cet6 where word='a';
if @t_count > 0 then
update set cet68=2,total=total+2 where word='a';
else
insert into cet6(word,total,cet68) values('a',2,2);
end; 把上面的语句块代码建立个存储过程执行就可以了。
2、
declare t_count int unsigned default 0;
select count(id) into t_count from cet6 where word='a';
if t_count> 0 then
update cet6 set cet68=2,total=total+2 where word='a';
else
insert into cet6(word,total,cet68) values('a',2,2);
end if;
设置你的 word 为主键或者唯一键。insert into cet6(word,total,cet68) values('a',2,2)
on duplicate key update cet68=2,total=total+2;