在不同行集上具有不同条件的联接语句 [英] Join statement with different conditions on different row set

查看:85
本文介绍了在不同行集上具有不同条件的联接语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在不同的行集上使用不同的条件联接两个表.

I need join two tables using different conditions on different row sets.

例如,如果RowID < 100 on t1.ColA = t2.ColBRowID >= 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

尝试此解决方案.

这篇关于在不同行集上具有不同条件的联接语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆