我正在查询mysql表并希望按日期分组结果,并且一个列名是type。类型call
和email
有两个值。我希望每天都能找到call
和email
的计数。
我正在尝试使用此查询。这只能得到我的总数:
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)
答案 0 :(得分:1)
请改用SUM()
。函数中的type='email'
返回0(假)或1(真)。
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)