Select
DATE_FORMAT(calls.call_datetime, "%Y-%m-%d") as `groupdate`
from
calls
WHERE calls.job_id =1
group by DATE_FORMAT(calls.call_datetime,
"%Y-%m-%d")
Select DATE_FORMAT(calls.call_datetime, "%Y-%m-%d") as groupdate , count(*)
from calls
WHERE calls.job_id =1
group by DATE_FORMAT(calls.call_datetime, "%Y-%m-%d")
SELECT COUNT(*) FROM calls WHERE ...; -- delivers "2"
SELECT COUNT(*) FROM calls WHERE ...; GROUP BY DATE(datetime) -- also delivers "2"
SELECT COUNT(DISTINCT DATE(call_datetime)) FROM calls WHERE ...; -- delivers "1"
Select
COUNT(*) as Result
from
calls
WHERE calls.job_id =1
group by DATE_FORMAT(calls.call_datetime, "%Y-%m-%d")
或者是一个传递表的方法
SELECT
COUNT(*) as Result
FROM (
Select
DATE_FORMAT(calls.call_datetime, "%Y-%m-%d") as `groupdate`
from
calls
WHERE calls.job_id =1
group by DATE_FORMAT(calls.call_datetime, "%Y-%m-%d")
) AS a
Select
Count(DATE_FORMAT(calls.call_datetime, "%Y-%m-%d")) as `groupdate`
from
calls
WHERE calls.job_id =1
group by DATE_FORMAT(calls.call_datetime,
"%Y-%m-%d")
4条答案
按热度按时间2admgd591#
您应该使用count()
nue99wik2#
这个问题模棱两可。因为一个日期有两行,所以期望的答案是“2”吗?如果不止一次约会呢?
t40tm48m3#
最简单的方法是使用
或者是一个传递表的方法
两个查询都应返回所需的相同预期结果。
btqmn9zl4#
尝试: