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

Results of the query

Results of the query

 

SELECT
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”
FROM (a
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 Overflowhttp://stackoverflow.com/questions/10692153/mysql-select-need-count-if-field-less-than-0-and-greater-than-0Is 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.
Top Search Terms:
  • greater than count distinct case when ] (2)
  • where organizationlevel count is greater than or equal to 15 sql (1)
  • how to count less than , greater than values in sql (1)
  • countif occurrences less than (1)
  • countif occurrence is greater than (1)
  • count with greater than and less than sql (1)
  • count if occurrences greater than 3 (1)
  • count if greater than or equal to (1)
  • chack value count greater than zero and equal to spacefic value mysql (1)
  • canopy count greater than (1)

Leave a Reply

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