还有就是你说的2条insert(当然此处不清除你的【owner1_id的值能匹配到common表中gid】是什么意思):insert into A (gid, onwer1_id, onwer2_id) select gid, onwer1_id, onwer2_id from common where ((owner1_id = 0 or owner1_id is null) and (owner2_id = 0 or owner2_id is null) ) or (owner1_id is not null and owner1_id != 0 and owner2_id is not null and owner2_id != 0 and ...);insert into B (gid, owner1_id, owner2_id) select gid, owner1_id, owner2_id from common where (owner1_id is not null and owner1_id != 0 and ...) or (owner2_id is not null and owner2_id != 0 and ...); --上面的...表示你的匹配条件
insert all when ... then ... into ... select ...
就是owner1_id=gid 能查出结果的,第一个插入那里要加上一个子查询 and owner1_id not in( select gid from common)这样,我明天把代码粘出来,总之查的结果总是过滤不了owner1_id有值,owner2_id又为空的。
(gid, onwer1_id, onwer2_id)
select gid, onwer1_id, onwer2_id
from common
where ((owner1_id = 0
or owner1_id is null)
and (owner2_id = 0 or owner2_id is null)
)
or (owner1_id is not null and owner1_id != 0 and
owner2_id is not null and owner2_id != 0 and ...);insert into B
(gid, owner1_id, owner2_id)
select gid, owner1_id, owner2_id
from common
where (owner1_id is not null and owner1_id != 0 and ...)
or (owner2_id is not null and owner2_id != 0 and ...);
--上面的...表示你的匹配条件
when ... then ... into ...
select ...