update my_table a
set string =
(select string from big_table where a.id = id )
--出错select stat from big_table where a.id = id
这条语句会返回很多条数据,我只要选择其中 stat = 1 且 seq_id 最大的那一条。把这条string赋值给my_table.string请教,怎样用一条语句完成?而且效率最好能高些。
数据多的时候有40W条。表的结构
big_table.id
big_table.string
big_table.seq_id
big_table.statmy_table.id
my_table.string跪谢!!!!!
set string =
(select string from big_table where a.id = id )
--出错select stat from big_table where a.id = id
这条语句会返回很多条数据,我只要选择其中 stat = 1 且 seq_id 最大的那一条。把这条string赋值给my_table.string请教,怎样用一条语句完成?而且效率最好能高些。
数据多的时候有40W条。表的结构
big_table.id
big_table.string
big_table.seq_id
big_table.statmy_table.id
my_table.string跪谢!!!!!
update my_table a
set string = (select string
from big_table b
where a.id = b.id
and seq_id = (select max(seq_id)
from big_table c
where b.id = c.id
and stat = 1)
from big_table b
where a.id = b.id
and seq_id = (select max(seq_id)
from big_table c
where b.id = c.id
and stat = 1)如果seq_id没有唯一约束,可能会查询出多条记录,会导致语句报错