前提:
1。结果集Table1(Table类型)
2。结果集Table2(Table类型)
3。Table1,Table2结构完全相同
4。X代表完全相同,Y代表按一定条件相同
结果集Table1
A1
B1
C1
D1
结果集Table2
A2
B2
C2
D2
要求
字段1 字段2 条件(满足条件即为相同)
A1 A2 X(A1=A2)
B1 B2 X (B1=B2)
C1 C2 Y (C1>C2)
D1 D2 Y ( A1<A2)
对比的结果插入Table3中
table3 包含
1。序号(table1与table2 对比的字段序号)
2。table1对比字段
3。table2对比字段
4。对比结果(一致0,不一致1)
目前自己想的方法是
select into table3 from
select '1',
a.A1,
b.A2,
case when a.A1=b.A2 then 0 else 1 end
from table1 a left join table2 b on a.id=b.id
union all
select into table3 from
select '2',
a.B1,
b.B2,
case when a.A1=b.A2 then 0 else 1 end
from table1 a left join table2 b on a.id=b.id
.
.
.
依次类推,case when中写条件union all一起,然后插入table3中
这样写的,请问大神们还有没有好点的方法???
谢过了!!!
insert into compare( id, aResult, bResult, cResult, dResult )
select
contact( T1.id, '-', T2.id ) id,
(T1.A = T2.A) aResult,
(T1.B = T2.B) bResult,
(T1.C > T2.C) cResult,
(T1.D < T2.D) dResult
from T1, T2
where
T1.A = T2.A and T1.B = T2.B and T1.C > T2.C and T1.D < T2.D
看看这种想法可以吗。
其实有点没太懂最后要表示成什么样子,比如T1( 'id1', 1, 2, 3, 4 ), T2( 'id2', 1, 3, 1, 5 )的话,T3要表示成什么样子呢