在不同行集上具有不同条件的联接语句
问题描述:
我需要在不同的行集上使用不同的条件联接两个表.
I need join two tables using different conditions on different row sets.
例如,如果RowID < 100 on t1.ColA = t2.ColB
和RowID >= 100 on t1.ColA = t2.ColB+1
我实现了如下:
... On (RowID <100 and t1.ColA=t2.ColB) OR (RowID >=100 on t1.ColA=t2.ColB+1) ...
但是它非常慢,所以问题出在哪里,更好的解决方案是什么?
But it's very very slow, so what is the problem and what is the better solution?
答
RowID <100 on t1.ColA=t2.ColB
UNION ALL
If RowID >=100 on t1.ColA=t2.ColB+1
尝试此解决方案.