在SQL查询

时间:2016-02-04 07:28:15

标签: sql sql-server sql-server-2008

如何使此查询使用Not in条件而不是整个表格,但限制每个客户的条件

SELECT 
    dbo.Service.Service_ID
    ,dbo.Service.Service_RNO
    ,dbo.Customer.Cust_Name
    ,dbo.Service.Agrement_ID
    ,dbo.Customer.Cust_ID
    ,dbo.Service.Service_Date
    ,dbo.Service.Next_Service
FROM
    dbo.Service
INNER JOIN 
    dbo.Customer ON dbo.Service.Cust_ID = dbo.Customer.Cust_ID
WHERE 
    Next_Service BETWEEN '2016-01-01' AND '2016-02-01'
    AND Next_Service NOT IN (SELECT Service_Date from Service)
ORDER BY 
    Next_Service

例如,让我说我有这个数据

Service_ID  Service_RNO Cust_Name   Agrement_ID Cust_ID Service_Date    Next_Service
1                 1       customer1    35         15     2016-01-01     2016-01-31
2                 2       customer1    35         15     2016-01-31     2016-03-2
3                 3       customer2    12         21     2016-01-31     2016-03-2
由于下一个服务存在于service_date

中,因此

此查询的输出将为空

该查询应该为客户提供2行数据,因为该客户Next_Service中不存在service_date

1 个答案:

答案 0 :(得分:3)

假设我理解这个问题:

questionPromise.then(() => {
    return new Promise((resolve) => {
        setTimeout(() => {
            console.log('second 2');resolve();
        }, 2000);
    })
});