i have this database table name clicks
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
my quesion is how to count clicks by every day by userID
i want output like
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
hope my question is clear
Try this with count()
SELECT userid ,
COUNT(userid) clicks,
`date`
FROM `table`
GROUP BY `date`,userid
A simple Group By clause will do:
SELECT userid, count(id) as clicks, date
FROM table
GROUP BY userid, date
ORDER BY date, userid
Don't forget to include the userid
in the grouping.
SELECT userid ,COUNT(id) as clicks,`date`FROM `table` GROUP BY `date`,userid
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.