| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 559 人关注过本帖
标题:为什么选出的记录条数和更新的记录条数不一样?
只看楼主 加入收藏
关小彤
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2006-12-7
收藏
 问题点数:0 回复次数:5 
为什么选出的记录条数和更新的记录条数不一样?
select * from forums_ksbm a, result b where
a.bknbcode_id=b.leibie and a.stuid_actived=1 and area!=20
and left(b.sfzh,6)=left(a.id_card,6)
and len(b.sfzh)=15 and len(a.id_card)=18
and substring(a.id_card,9,6)=substring(b.sfzh ,7,6)

所影响的条数是956行
update result set result.sign=1 from forums_ksbm a, result b where
a.bknbcode_id=b.leibie and a.stuid_actived=1 and area!=20
and left(b.sfzh,6)=left(a.id_card,6)
and len(b.sfzh)=15 and len(a.id_card)=18
and substring(a.id_card,9,6)=substring(b.sfzh ,7,6)

所影响的条数是945条
为什么会这样呢?
谢谢
搜索更多相关主题的帖子: 记录 
2007-05-14 16:55
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
收藏
得分:0 

你把第一个的956条写进临时表
然后和第2个的945条比较一下 不就知道那不一样的11条是什么了


2007-05-14 17:32
棉花糖ONE
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:32
帖 子:2987
专家分:0
注 册:2006-7-13
收藏
得分:0 

update result set result.sign=1 from forums_ksbm a where
a.bknbcode_id=result.leibie and a.stuid_actived=1 and area!=20
and left(result.sfzh,6)=left(a.id_card,6)
and len(result.sfzh)=15 and len(a.id_card)=18
and substring(a.id_card,9,6)=substring(result.sfzh ,7,6)
直接这样写,看看更新几条


26403021 sql群 博客 blog./user15/81152/index.shtml
2007-05-14 18:50
关小彤
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2006-12-7
收藏
得分:0 
棉花糖斑竹,用你的语句更新的是945条记录
为什么会出现这种情况呢?

2007-05-14 19:50
关小彤
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2006-12-7
收藏
得分:0 
我把选出的数据放入一个临时表发现有十一条记录时重复的。是什么造成临时表中有重复数据呢?我不太明白。
谢谢!

2007-05-14 20:07
棉花糖ONE
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:32
帖 子:2987
专家分:0
注 册:2006-7-13
收藏
得分:0 

select * from forums_ksbm a, result b where
a.bknbcode_id=b.leibie and a.stuid_actived=1 and area!=20
and left(b.sfzh,6)=left(a.id_card,6)
and len(b.sfzh)=15 and len(a.id_card)=18
and substring(a.id_card,9,6)=substring(b.sfzh ,7,6)

这个选出来的有重复数据

create table test1(id int,score int)
insert into test1 select 1,90
union all select 1,90
union all select 2,75

create table test2(id int,score int)
insert into test2 select 1,74

select * from test1,test2 where test1.id=test2.id //选出来的是两条记录

update test2 set test2.score=t.score from test1 t where test2.id=t.id //显示只更新一行


26403021 sql群 博客 blog./user15/81152/index.shtml
2007-05-20 15:40
快速回复:为什么选出的记录条数和更新的记录条数不一样?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015571 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved