Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL条件的_Sql - Fatal编程技术网

SQL条件的

SQL条件的,sql,Sql,我有一个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) 我需要有一个条件,如果t1.field02等于AX,我必须读取第

我有一个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)
我需要有一个条件,如果t1.field02等于AX,我必须读取第二个文件lib02/SecondFile,如果t1.field02等于BX,我必须读取第三个文件lib02/ThirdFile

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的旧语法

您使用的是哪种DBMS?您应该真正停止在where子句中使用那些古老的、过时的、脆弱的隐式连接,而是使用显式连接运算符