我有一个带有表格答案的小游戏数据库: 每个用户每天最多可以玩2次, 表格答案结构如下:
UID | ANSWER | DATE
我想查询一下每天至少播放一次的用户数量。 我做了类似的事情,但这不起作用。
SELECT Day(date) as n,
Dayname(date) as m,
uid,
COUNT(uid) as c
FROM answers
WHERE Year(date) = '2012'
GROUP BY uid HAVING count( * ) <=2 //COUNT user who played at least 2 times per day
GROUP BY n //group by day
ORDER BY n
我希望得到这样的结果:
Friday | 9-5-2012 | 1254
Saturday | 10-5-2012 | 1427
...
任何帮助表示赞赏...
答案 0 :(得分:0)
而不是两个group by
子句,使用一个在一天分组的单词:
select day(date) as d
, month(date) as m
, count(distinct uid) as c
from answers
where year(date) = '2012'
group by
day(date)
, month(date)
having count(*) > 1