我正在尝试做类似
的事情SELECT `v1`.`date`, COUNT(DISTINCT(`v2`.`id`)) AS `visits`
FROM `visitor_visits` AS `v1` JOIN `visitor_visits` AS `v2`
ON (`v1`.`date` = `v2`.`date`) GROUP BY `v1`.`date`, `v2`.`date`
ORDER BY `v1`.`date
获取不同的日期,以及匹配的所有其他日期的计数。
我很确定这是错误的查询,因为日期列是非唯一的。
答案 0 :(得分:2)
出了什么问题:
SELECT v1.date, COUNT(v1.id) AS visits
FROM visitor_visits AS v1
GROUP BY v1.date
ORDER BY v1.date
PS。我假设id
是主键(唯一)。
答案 1 :(得分:0)
如果您要查看每个日期的不同访客ID,则应该只是
SELECT v1.date,
COUNT(DISTINCT(v1.id)) as Visitors
FROM
visitor_visits AS v1
group by
v1.Date