表1和表2结构一样,如下:
表1
zh yc pos
8 1426
10 1519
10 1519
10 1520
表2
zh yc pos
8 1426 2
8 1426 2
8 1427 3
8 1428 6
10 1519 4
10 1519 4
10 1520 6
10 1521 8
现在要将表2中pos数值更新到表1中,作到如下效果
zh yc pos
8 1426 2
10 1519 4
10 1519 4
10 1520 6
就是当表1中zh,yc两个字段和表2中zh,yc两个字段相等时更新表2的pos字段到表1中
由于数据中有重复数据,不知道怎么办才好,写的语句无法使用
update 表1 set pos=表2.pos(select 表2.pos from 表2,表1 where 表1.zh=表2.zh and 表1.yc=表2.yc)
感觉语法上面应该这么写,不过有重复数据不知道怎么解决,请高手指点下
表1
zh yc pos
8 1426
10 1519
10 1519
10 1520
表2
zh yc pos
8 1426 2
8 1426 2
8 1427 3
8 1428 6
10 1519 4
10 1519 4
10 1520 6
10 1521 8
现在要将表2中pos数值更新到表1中,作到如下效果
zh yc pos
8 1426 2
10 1519 4
10 1519 4
10 1520 6
就是当表1中zh,yc两个字段和表2中zh,yc两个字段相等时更新表2的pos字段到表1中
由于数据中有重复数据,不知道怎么办才好,写的语句无法使用
update 表1 set pos=表2.pos(select 表2.pos from 表2,表1 where 表1.zh=表2.zh and 表1.yc=表2.yc)
感觉语法上面应该这么写,不过有重复数据不知道怎么解决,请高手指点下
select distinct 表2.pos from 表2,表1 where 表1.zh=表2.zh and 表1.yc=表2.yc
这个单独执行正常的,不过连起来
update 表1 set pos=表2.pos(select distinct 表2.pos from 表2,表1 where 表1.zh=表2.zh and 表1.yc=表2.yc)
报刚刚说的哪个错误,缺少表达式,我改成
update 表1 set pos=(select distinct 表2.pos from 表2,表1 where 表1.zh=表2.zh and 表1.yc=表2.yc)
报ora-01427:单行子查询返回多个行,何解?问题出那里?
报ora-01427:单行子查询返回多个行,何解?问题出那里?
1, select distinct 表2.pos from 表2,表1 where 表1.zh=表2.zh and 表1.yc=表2.yc)这个子查询中查出多条记录
2, 解决办法update 表1 set pos=(select distinct 表2.pos from 表2 a,表1 b where a.zh=b.zh and a.yc=b.yc and b.rowid=表1.rowid) 改成这样试试
胜读好几本书啊!!!