现在有两张表,一张user主要的字段有username,usercode,depname,depid,adress,phone.一张是user_temp字段相同,但是没有ID相对应.两张表通过usercode和depid来确定是否同一条记录.
现在需要做的有:一是统计有多少条需要更新(usercode,depid相同,其它有一个或者多个字段不同),多少需要删除(usercode,depid在user表中有,在user_temp没有),多少需要插入(与删除相反);
二是,怎么样执行上面的更新,插入和删除.
现在需要做的有:一是统计有多少条需要更新(usercode,depid相同,其它有一个或者多个字段不同),多少需要删除(usercode,depid在user表中有,在user_temp没有),多少需要插入(与删除相反);
二是,怎么样执行上面的更新,插入和删除.
解决方案 »
- 关于Information_schema和Mysql库的问题.
- mysql where in 查询 大家帮忙下
- 翻译 Twin Project
- mysql问题,高手帮忙分析一下
- SQL 锁
- 使用mysql编程,调用了mysql_query后能否取消
- 比如说我有4个字段的值分别是:'我是一号','我是二号','我是三号','我四号',查询是只输入'是'字,我想返回所有带'是'的字段,这样的SQL
- [菜鸟醒目]关于查询问题,很简单,有分
- mysql如何获取时间段内每一天的结果集,没有时为O
- MySQL 中如何根据表 ID 中隐藏的时间戳按天进行分区?
- MYSQL停止/启用不了
- 异地试图自动同步一个视图
select count(*) number from user a left join user_temp b on a.userflag=b.userflag and a.depid=b.depid where b.userflag is null and b.depid is null
select count(*) number from user_temp a left join user b on a.userflag=b.userflag and a.depid=b.depid where b.userflag is null and b.depid is null
explain select count(*) number from user a,user_temp b where a.userflag=b.userflag and a.depid=b.depid and ( a.username!=b.username or a.depname!=b.depname)
explain select count(*) number from user a left join user_temp b on a.userflag=b.userflag and a.depid=b.depid where b.userflag is null and b.depid is null
explain select count(*) number from user_temp a left join user b on a.userflag=b.userflag and a.depid=b.depid where b.userflag is null and b.depid is null 结果看一下,分析优化。