MySQL查询的Strang问题
我正在尝试查找以下查询返回的行数:MySQL查询的Strang问题,mysql,function,count,Mysql,Function,Count,我正在尝试查找以下查询返回的行数: SELECT Count(id) AS fcount, user_id FROM customer_followups WHERE id > 0 AND Date(followup_date) >= Str_to_date("24-09-2012", "%d-%m-%y") AND Date(followup_date) <= Str_to_date("24-09-2012", "%d
SELECT Count(id) AS fcount,
user_id
FROM customer_followups
WHERE id > 0
AND Date(followup_date) >= Str_to_date("24-09-2012", "%d-%m-%y")
AND Date(followup_date) <= Str_to_date("24-09-2012", "%d-%m-%y")
GROUP BY user_id
ORDER BY user_id
选择Count(id)作为fcount,
用户id
来自客户跟踪
其中id>0
和日期(后续日期)>=截止日期(“2012年9月24日,%d-%m-%y”)
和日期(后续日期)0
和日期(后续日期)>=截止日期(“2012年9月24日,%d-%m-%y”)
和Date(followup_Date)给出满足条件的组的记录数
The COUNT function is an aggregate function that simply counts all the items that
are in a group.
而在第二个查询中,您只找到该组的id和用户id。请记住,如果组具有不同的用户id,它将返回其中任何一个,以查找您可以使用的所有用户id,即组CONCAT(用户id)COUNT
统计由group
@ravincarible统一的行数:这两个查询都应返回相同的行数。该数字应与表中不同的用户id
相同。不过,第二个查询相当无用,因为它将为每个用户返回(或多或少)随机id
。是的,我100%确定2012年9月24日只有一条记录。但是MYSQL仍然失败,count函数返回5。是的,我知道count是如何工作的,对于上面的查询,所提到的日期范围只有1条记录。
The COUNT function is an aggregate function that simply counts all the items that
are in a group.