加入多个大表

时间:2012-02-03 16:55:32

标签: sql sybase

我有三张桌子

Table T1: Columns {a,b,c}, combination {a,b} is unique in Table T1
Table T2: Columns {a,c,d}, combination {a,c} is unique in Table T2
Table T3: Columns {a,c,e}, combination {a,c} is unique in Table T3

其中{a,b,c}是字符串,{d,e}是数字

我希望我的输出

Table T4: Columns {a,b} where e/d < x.

表T1,T2,T3都非常大(数百万行),所以我实现这个的方法是在表T1 T2上执行左连接并将结果保存到临时表,然后执行左连接表T1 T3并保存结果,然后对结果进行左连接,最后将这些临时表组合成1个最终表。

我的问题是,有没有更好/更有效的方法来做到这一点而不会炸毁数据库?

1 个答案:

答案 0 :(得分:1)

您是否尝试过直接的方式?

select t1.a, t1.b
into t4
from t1
join t2 on t1.a = t2.a and t1.c = t2.c
join t3 on t1.a = t3.a and t1.c = t3.c
where t3.e / t2.d < x

在临时表中存储数百万条记录不利于性能或存储......