0

我有两个 sql 查询

SELECT sub_id, 
       sub_sent_code, 
       date_time 
FROM   moviedatabase.reg_sub_master 
WHERE  (date_time >= '2013-01-19' 
         AND date_time <= '2013-01-29');

SELECT sub_id, 
       sub_sent_code, 
       date_time 
FROM   moviedatabase.reg_sub_master 
WHERE  date_time <= '2013-01-19'; 

我的要求是从第一次查询中得出的结果sub_id,sub_sent_code,date_time不应该出现在第二次查询中。

我想让它成为单个查询。

编辑:实际上我想要的结果date_time >='2013-01-19'和我得到date_time <='2013-01-29'的结果sub_id不应该是以前的'2013-01-19'

4

1 回答 1

4

尝试 :

SELECT sub_id,sub_sent_code,date_time
FROM   moviedatabase.reg_sub_master
WHERE  (date_time >='2013-01-19' 
    AND date_time <='2013-01-29')
    AND sub_id NOT IN (
        SELECT DISTINCT sub_id
        FROM   moviedatabase.reg_sub_master
        WHERE  date_time <='2013-01-19;
于 2013-01-24T08:32:54.680 回答