我需要找出每天唯一访客的数量,我有这样的数据库:
UID clicks date
6046 9 2013-03-06
6449 7 2013-03-06
6450 41 2013-03-06
664 2 2013-03-07
2432 36 2013-03-07
3246 11 2013-03-07
6031 52 2013-03-07
现在我需要找到每天的唯一访问者数量。我发现这一点以及当天的点击次数。所以查询是这样的:
SELECT date,SUM(clicks) as new_clicks,COUNT(DISTINCT uID) as unique_clicks
FROM uc_user
WHERE date <='2013-03-15' GROUP BY date;
但是在这里我得到了错误的结果。计数与我使用相同间隔计算的计数不同
SELECT date, COUNT(DISTINCT uID ) AS unique_clicks
FROM uc_user
WHERE date <= '2013-03-15'
GROUP BY date
LIMIT 0 , 30
这些查询之间有什么区别,哪一个对于显示唯一访问者的数量是正确的?
实际上我在 PHP 中的实际查询是这样的:
SELECT date,SUM(clicks) as new_clicks,COUNT(uID) as unique_clicks
FROM currencyclick_user
WHERE date BETWEEN '$from' AND '$to'
GROUP BY date
和
SELECT SUM(clicks) as total_new_clicks,
COUNT(DISTINCT uID) as total_new_uniqueclicks
FROM currencyclick_user
WHERE date BETWEEN '$from' AND '$to'
但对于相同的范围,它显示不同的值。我的意思是总和查询显示的总数比我通过在第一个查询中添加计数得到的值错误。