我有一个相关的子查询SQL语句:

 SELECT AccountNo, AccountDescription
 FROM [AP].[dbo].GLAccounts AS Inv_Main
 WHERE NOT EXISTS
     (Select *
    FROM [AP].[dbo].Vendors AS Inv_Sub
    WHERE Inv_Main.AccountNo = Inv_Sub.DefaultAccountNo)
 ORDER BY AccountNo;


我将如何显示每个以#3开头的帐户的结果(例如300,301,302 ..)。我该怎么做?是否在...和...之间添加子句?

最佳答案

您可以将其添加为WHERE子句的一部分。

 SELECT
 AccountNo,
 AccountDescription
 FROM [AP].[dbo].GLAccounts AS Inv_Main
 WHERE
 (
     NOT EXISTS
     (
         Select *
         FROM [AP].[dbo].Vendors AS Inv_Sub
         WHERE
         (Inv_Main.AccountNo = Inv_Sub.DefaultAccountNo) AND
         (Inv_Main.AccountNo BETWEEN 299 AND 400)
     )
 )
 ORDER BY AccountNo;

关于mysql - SQL-我将如何在NOT EXIST语句中显示以3s(例如300,301,302 ..)开头的每个帐户的结果?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26351695/

10-09 15:50