Count occurrences both greater than, less than, or equal in MySQL

Results of the query

Results of the query


COUNT(recycled) AS “Total”,
SUM(CASE WHEN recycled = 1 THEN 1 ELSE 0 END) AS “New”,
SUM(CASE WHEN recycled > 1 THEN 1 ELSE 0 END) AS “Recycled”
SELECT phone_number, count(*) AS recycled, sale_date FROM ( SELECT DISTINCT * FROM ( SELECT customers.phone_number, customers.sale_date FROM customers INNER JOIN ( SELECT customers.phone_number FROM customers WHERE sale_date BETWEEN ‘2014-05-23’ AND ‘2014-05-30’) list on customers.phone_number = list.phone_number ORDER BY phone_number DESC, sale_date DESC ) AS multiple_sales ) AS sale_dates_analysis GROUP BY phone_number ORDER BY sale_date DESC) AS phone_count

Helpful link at StackExchange:

php – MySQL select need count if field less than 0 and greater than 0 – Stack Overflow there a way to write a mysql select statement to run a count for a particular 1 field only, if greater than zero and equal to zero.

Leave a Reply

Your email address will not be published. Required fields are marked *