1

我有一个带有表格答案的小游戏的数据库:每个用户每天最多可以玩和回答 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 ...

任何帮助表示赞赏...

4

1 回答 1

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
于 2012-09-17T14:06:02.550 回答