0

I am querying a mysql table and want results group by date, and one column name is type. There are two value for the type call and email. I want to find count for call and email for each day.

I am trying with this query. Which only gets me total counts:

SELECT Date(date) date,
COUNT(type) total,
COUNT(type='email') emails,
COUNT(type='call') calls

from leads 
where user_id = 1 
GROUP BY Date(date)

1 Answer 1

1

Use SUM() instead. The type='email' in the function returns either 0 (false) or 1 (true).

SELECT Date(date) date,
COUNT(type) total,
SUM(type='email') emails,
SUM(type='call') calls
from leads 
where user_id = 1 
GROUP BY Date(date)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.