How to add a few restrictios to a query?

前端 未结 2 1737
我寻月下人不归
我寻月下人不归 2021-01-29 08:44

I have difficulty with syntax...

This is my query:

SELECT t.diapason,
       Count(*) AS \'number_of_users\'
FROM   (SELECT CASE
                 WHEN a         


        
2条回答
  •  梦毁少年i
    2021-01-29 09:09

    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;
    

提交回复
热议问题