select count(*) from a,b where a.id=b.id and
a.name=b.name and a.xx=b.xx;update a set flag=1 where exists (select * from b where a.id=b.id and
a.name=b.name and a.xx=b.xx);
这俩语句处理的是相同的纪录吗? select 出来3w条纪录;update了才1w条纪录,为什么?应该怎么修改?
a.name=b.name and a.xx=b.xx;update a set flag=1 where exists (select * from b where a.id=b.id and
a.name=b.name and a.xx=b.xx);
这俩语句处理的是相同的纪录吗? select 出来3w条纪录;update了才1w条纪录,为什么?应该怎么修改?
解决方案 »
- 求每年最小月份的金额合计和最大月份金额合计
- grant select any table to user_test提示权限不足?
- 大家帮忙看一个问题啊
- 求将Oracle库中某几张表同步到Sqlite库的软件或实现方法
- 关于建视图后,number型字段长度没有了的问题?急!
- 菜鸟初学,有个问题各位大哥给帮帮忙!
- oracle维护分哪几种维护级别?报价标准是什么?
- 什么工具开发PL/SQL最好
- 几个关于数据库导出的问题,请指教.
- 请教一个简单SQL语句,在线等待……急!急1急!……
- 怎么把这几个update语句整成一句呢?
- 求在centOS4.2下,文本方式(用命令行)来安装oracle9i的办法
修改一下这样试试:
update a set flag=1 where id in (select a.id from a,b where a.id=b.id and
a.name=b.name and a.xx=b.xx);
1. select count(*) from a,b where a.id=b.id and a.name=b.name and a.xx=b.xx;
做的是笛卡尔集,就是说这个select的结果集里A表的数据有可能是重复的.2. where exists (select * from b where a.id=b.id and a.name=b.name and a.xx=b.xx);
这句只是要求更新A表在B表中存在的即可,和Select不一样,A不会重复.所以楼主原来的写法是正确的.
下面语句的结果才和update 等价,其结果应该是1w 条。
select count(distinct a.flag ) from a,b where a.id=b.id and
a.name=b.name and a.xx=b.xx;
select count(*) from (select * from a,b where a.id=b.id and
a.name=b.name and a.xx=b.xx)看看有几条记录
a:表
字段1 字段2 字段3
1 2 3b:表
字段1 字段2 字段3 字段4
1 2 3 4
1 2 3 5这样你查询出来就是
1 2 3 1 2 3 4
1 2 3 1 2 3 5
有两条记录
然后你的update语句,当然就是处理a表的那一条记录了
明白了么?