B
B
bredd2017-09-28 19:26:51
PHP
bredd, 2017-09-28 19:26:51

How to make a sample of lost customers?

There is a database with all orders
phone, id, price, accept
, the client's phone number, order ID, order amount, date-time of the order.
You need to make a selection (unique phone numbers) for customers who:

  1. made at least 2 orders in the last 120 days
  2. but have not made any order in the last 30 days

How to do this with a MySQL query?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Skibin, 2017-09-28
@megafax

SELECT `phone`, count(`id`) as `count`
FROM `orders`
WHERE `accept` >= NOW() - INTERVAL 120 DAY AND `accept` <= NOW() - INTERVAL 30 DAY
GROUP BY `phone`
HAVING `count` >= 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question