MySQL query help needed to get clients who haven't bought anything in more than 180 days! -
i have table orders stores info orders(including ordersname,orderssurname,ordersemail,ordersphone) info need get.
it contains field ordersfinishedtime datetime field stores data when order finished.
what need select ordersname,orderssurname,ordersemail,ordersphone orders table users haven't bought in more 180 days.
that - need find unique users who's last unique purchase more 180 days ago.
thanks in advance!
edit:
i know how find records order 180 days, need records 180 days older , there no more orders(for particular user) after date!
edit2: not reading question through. need find unique users haven't purchased in more 180 days. don't need orders older 180 days, need user info stored in orders.
my current sql query this:
select distinct o.ordersemail
,o.ordersname
,o.orderssurname
,o.ordersphone
,o.ordersfinishedtime
(select ordersphone
, max(ordersfinishedtime
) ordersfinishedtime
orders
year(ordersfinishedtime
) >= 2010 group ordersphone
having datediff(now(),max(ordersfinishedtime
)) >= 180) lastorders inner join orders
o using(ordersphone
,ordersfinishedtime
) order ordersfinishedtime
desc
try this:
select `ordersname`, `orderssurname`, `ordersemail`, `ordersphone` `orders ` `ordersfinishedtime` < subdate(now(), 180);
Comments
Post a Comment