SQL JOIN ON(有两个条件)

时间:2018-10-18 16:17:18

标签: sql oracle join

我想知道是否有可能在on()条件下编写一个将两个表与两个CASE WHEN连接起来的SQL ORACLE命令;我尝试过这种方式;但这没用

SELECT *
FROM A  a
   LEFT OUTER JOIN B b
       ON ((CASE
                WHEN LENGTH (a.xxx) = 3
                THEN a.xxx
                WHEN LENGTH (a.yyy) = 2
                THEN TO_CHAR (a.xxx || TRUNC (a.zzz, 'YY'))
            END) **=**
           (CASE
                WHEN LENGTH (a.xxx) = 3 THEN b.wert
                WHEN LENGTH (a.xxx) = 2 THEN b.bez
            END));

1 个答案:

答案 0 :(得分:1)

这是您想要的逻辑吗?

public function index(Request $request) {
    Log::info($request->bearerToken());
    // ...
}
布尔表达式通常不需要

on (length(a.xxx) = 3 and a.xxx = b.wert) or (length(a.xxx) = 2 and (a.xxx || TRUNC(a.zzz, 'YY')) = b.bez) 表达式。