每天查询数据

时间:2014-02-19 11:07:20

标签: php mysql

我有这个数据库表名点击

id  userid  siteID  date
1   3       1       2014-02-15
2   3       2       2014-02-15
3   3       3       2014-02-15
4   3       4       2014-02-15
5   3       5       2014-02-15
6   3       4       2014-02-16
7   3       5       2014-02-16
8   3       6       2014-02-16
9   3       7       2014-02-16
10  3       8       2014-02-16
11  3       9       2014-02-17
12  3       5       2014-02-17
13  3       4       2014-02-17
14  3       1       2014-02-17
15  3       1       2014-02-17
16  3       2       2014-02-18
18  3       3       2014-02-18
18  3       4       2014-02-18
19  3       7       2014-02-18
20  3       6       2014-02-18
21  3       1       2014-02-19
22  3       2       2014-02-19
23  3       3       2014-02-19
24  3       4       2014-02-19
25  3       5       2014-02-19
26  3       8       2014-02-19

我的问题是如何按用户ID计算每天的点击次数

我想输出

userid   clicks  date
3        5       2014-02-15
3        5       2014-02-16
3        5       2014-02-17
3        5       2014-02-18
3        5       2014-02-19

希望我的问题很清楚

3 个答案:

答案 0 :(得分:1)

使用count()

尝试此操作
SELECT userid ,
COUNT(userid) clicks,
`date`
FROM `table`
GROUP BY `date`,userid 

答案 1 :(得分:0)

一个简单的Group By子句可以:

SELECT userid, count(id) as clicks, date
FROM table
GROUP BY userid, date
ORDER BY date, userid

不要忘记在分组中加入userid

答案 2 :(得分:0)

SELECT userid ,COUNT(id) as clicks,`date`FROM `table` GROUP BY `date`,userid