I have difficulty with syntax...
This is my query:
SELECT t.diapason,
Count(*) AS \'number_of_users\'
FROM (SELECT CASE
WHEN a
You add WHERE
clause to filter.
SELECT t.diapason,
COUNT(*) AS 'number_of_users'
FROM (
SELECT
CASE
WHEN amount < 200 THEN '0-200'
WHEN amount >= 200 THEN '200 +'
END AS diapason
FROM (
SELECT payments.user_id, SUM(amount) AS amount
FROM payments
INNER JOIN activity ON payments.user_id = activity.user_idAND activity.login_time = payments.payment_time
WHERE activity.login_time BETWEEN '2018-01-10' AND '2018-01-12'
GROUP BY payments.user_id
) p
) t
GROUP BY t.diapason
ORDER BY number_of_users DESC;