mysql对同⼀个表select和update
mysql不会让你在对⼀个表进⾏update的同时运⾏select
变通的⽅式是衍⽣表,⽣成⼀张临时表。这样就可以既update⼜select
update tb_trade_1 inner join (select  tid ,count(*) as cnt  from tb_order_1 group by tid) as der using(tid) set
commission_fee= dert;
mysql中去除重复的数据
按常理来说,这个sql语句应该是:
delete tablename where id not in(select min(id) from tablename group by name,kecheng,fenshu);
这种写法在sqlserver或者oracle中是⽀持的,但是mysql⽬前是不⽀持的,会报类似错:You can't specify target table 'tablename'
for update ,这是因为在mysql中不能同时查询⼀个表的数据再同时进⾏删除.
delete  a.* from  tb_trade_0 as a,( select tid,count(*),min(id) as id  from tb_trade_0
group by tid  having count(*)>1 order by gmt_create desc) as b
where a.tid=b.tid and a.id > b.id;
DELETE a.* FROM `sites_cates` AS a LEFT JOIN `sites` AS b ON `a`.`site_id` = `b`.`sid` WHERE `b`.`name` IS NULL 这样不就简单了,mysql与oracle的不同点是mysql不能在从句中使⽤主句使⽤的表,但是oracle是可以的,这是mysql和oracle的sql的不同点之⼀
>mysql删除重复的数据保留一条

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。