2014-02-19 126 views
0

數據一天,我有這個數據庫表名點擊查詢通過

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 

我quesion是如何通過用戶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 

希望我的問題很明確

+2

你嘗試過什麼嗎? – Ramesh

+1

你到目前爲止嘗試過什麼嗎?你能發佈你迄今爲止的努力嗎? – Rikesh

+2

這個問題似乎是脫離主題,因爲它缺乏努力 – Strawberry

回答

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

試試這個吧count()

SELECT userid , 
COUNT(userid) clicks, 
`date` 
FROM `table` 
GROUP BY `date`,userid 
+0

@downvoters關心解釋 –

0

一個簡單的Group By條款會做:

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

不要忘了,包括在分組中userid