我有一张用户访问的表格
id | visitorid | date | ..
1 | 12345 | 01-01-2013
2 | 12345 | 01-01-2013
3 | 12345 | 01-01-2013
4 | 99999 | 01-01-2013
...
35 | 243246 | 01-02-2013
..
我想获得一个月的独特访问,所以这样的输出
day | u_visits
1 | 33
2 | 42
3 | 7
首先,我想通过visitorid进行分组(每天),然后按月份分组。但是当我试图将两者分组时,结果完全错了:
SELECT day(date) AS days, COUNT(id) FROM table WHERE ... GROUP BY visitorid, days
任何人都知道出了什么问题?
答案 0 :(得分:0)
SELECT
DAY(date) AS days,
COUNT(DISTINCT(visitorid)) AS `Unique visits`
FROM visits
GROUP BY days
此处有一个fiddle。