两列之间范围的 MS Access 匹配

MS Access Match from Range between two columns

我有 table T1 如下

RL  OR  FVALU   TVALU
R1  O1  3291    
R1  O1  3002    
R1  O1  3010
R2  O1  2000

和另一个 Table T2 如下:

RL  OR  FVALU   TVALU
R1  O1  3291    
R1  O1  3000    3005
R1  O1  5000    
R2  O1  *

预期输出应如下所示:

RL  OR  FVALU   TVALU   MATCHORDOESNOT
R1  O1  3291            MATCH
R1  O1  3002            MATCH
R1  O1  3010            DONOTMATCH
R2  O1  2000            MATCH

============================================= ================== 如何匹配 FVALU 和 TVALU 字段中从 T1 到 T2 的值?

在上述情况下,3002 和 3291 应在 T1 和 T2 table 之间匹配 * 值应与 2000 匹配。前两列可以有连接。另外,请注意 TVALU 有时有值,有时为 Null

我试过以下查询但没有用:SELECT T1.RL, T1.[OR], T1.FVALU, T1.TVALU, IIf(InStr(([T2]![FVALU]),"*")>0,"MATCH",IIf([T1]![FVALU] Between ([T2]![FVALU]) And (IIf([T2]![FVALU] Is Null,[T2]![FVALU],[T2]![FVALU])),"MATCH","DONOTMATCH")) AS MATCHORDOESNOT FROM T1 INNER JOIN T2 ON (T1.[OR] = T2.[OR]) AND (T1.RL = T2.RL);

使用表的 LEFT 连接和 ON 子句中的所有条件:

SELECT DISTINCT T1.*,
       IIF(T2.RL IS NULL, 'DONOTMATCH', 'MATCH') AS MATCHORDOESNOT
FROM T1 LEFT JOIN T2
ON T2.RL = T1.RL AND T2.[OR] = T1.[OR]
AND (T2.FVALU = T1.FVALU OR (INSTR(T2.FVALU, '*') > 0) OR (T1.FVALU BETWEEN T2.FVALU AND T2.TVALU))

结果:

RL  OR  FVALU   TVALU   MATCHORDOESNOT
R1  O1  3002            MATCH
R1  O1  3010            DONOTMATCH
R1  O1  3291            MATCH   
R2  O1  2000            MATCH