sql - MySQL Query NOT IN another Query -
select distinct d.customer_id, d.date_added `order` d d.customer_id not in ( select distinct i.customer_id `order` i.date_added > '2015-02-15 14:00:00' ) order d.date_added desc;
the above query should return customer_id of customers have not ordered after 15 feb 2015 (i think). first record is
17168, 2015-08-16 17:36:00
what doing wrong?
this below query
select distinct i.customer_id,i.date_added `order` i.date_added > '2015-02-15 14:00:00' order i.date_added asc;
returns expected result i.e. list of customer ids orders placed after 15 feb
p.s. customer_id can not null
can customer_id
or data_added
null
? try
select distinct d.customer_id,d.date_added order d d.customer_id not in (select distinct i.customer_id order i.date_added > '2015-02-15 14:00:00' , customer_id not null , i.date_added not null) order d.date_added desc;
edit
the way wrote query customer_ids
order before '2015-02-15 14:00:00'. if customer ordered after date might in resultset.
edit2
why not write
select distinct customer_id, date_added order date_added <= '2015-02-15 14:00:00' order date_added desc;
Comments
Post a Comment