例如: t1(id int, c1 int, c2 int);
t2(id int, c1 int, c2 int, c3 int);
目的:将t1中的id列移到t2中的c3列,条件是 t1.c1 = t2.c1 and t1.c2 = t2.c2我试着写了一个:update t2 set t2.c3 = (select t1.id from t1 where t1.c1 = t2.c1 and t1.c2 = t2.c2)
where exists(select t1.id from t1 where t1.c1 = t2.c1 and t1.c2 = t2.c2);执行结果总是说...more then one rows(有点记不清了,回头补上), 好像是说set t2.c3 = 多行了请教各位大侠帮忙~
谢谢!
t2(id int, c1 int, c2 int, c3 int);
目的:将t1中的id列移到t2中的c3列,条件是 t1.c1 = t2.c1 and t1.c2 = t2.c2我试着写了一个:update t2 set t2.c3 = (select t1.id from t1 where t1.c1 = t2.c1 and t1.c2 = t2.c2)
where exists(select t1.id from t1 where t1.c1 = t2.c1 and t1.c2 = t2.c2);执行结果总是说...more then one rows(有点记不清了,回头补上), 好像是说set t2.c3 = 多行了请教各位大侠帮忙~
谢谢!
比如:t1:id c1 c2
1 3 3
2 4 4
3 5 5t2: id c1 c2 c3
1 3 3
2 4 4
3 5 5更新后:
t2为:id c1 c2 c3
1 3 3 1
2 4 4 2
3 5 5 3不知道我这样说清楚了没?
问题在于你在 t1 表中有重复的 c1,c2, 这个已经在一楼的回复中说明了。不知道我这样说清楚了没有。
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
嗯,是t2表里有重复的。比如:t1:id c1 c2
1 3 3
2 4 4
3 5 5t2: id c1 c2 c3
1 3 3
2 4 4
3 5 5
4 3 3
5 4 4更新后:
t2为:id c1 c2 c3
1 3 3 1
2 4 4 2
3 5 5 3
4 3 3 1
5 4 4 2如果这样的话,如何解决呢?
PS:我现在没法测试,等晚上才有条件~
我看了呀,你说的我也清楚,所以我又恢复加了些数据来说明我要实现的东西,怪我没有表达清楚,
相信LS已经清楚我的要实现什么, 我现在最想知道的是,如何即什么样的SQL能够解决我要实现的情况?
谢谢!