我有这个sql:
Select
t1.field01,
t1.field02,
t2.name02,
t2.surname02,
from
lib01/FirstFile as t1,
lib02/SecondFile (lib02/ThirdFile) as t2
where
t1.field01 = t2.field02 (or t3.filed02)
我需要条件if t1.field02 is equal to "AX"
我必须读取第二个文件(lib02 / SecondFile),if t1.field02 is equal to "BX"
我必须阅读第三个文件(lib02 / ThirdFile)。
答案 0 :(得分:0)
Select
CASE
WHEN ((Select t1.field02 from lib01/FirstFile as t1 ) = AX)
THEN Select t2.name02, t2.surname02
from lib02/SecondFile (lib02/ThirdFile) as t2
CASE
WHEN ((Select t1.field02 from lib01/FirstFile as t1 ) = BX)
THEN Select t3.name02, t3.surname02
from (lib02/ThirdFile) as t3
END
如果检索不是您想要的,那么在每个THEN
子句之后更改代码,但这就是逻辑。
尽量避免使用join