2010-10-17 109 views
0

我使用MySQL表像這樣的:Mysql的計數ID查詢

| userid | regdate | question | answer | 
----------------------------------------------- 
     1  2010-10-14 question 1 answer1 
     2  2010-10-14 question 2 answer2  
     3  2010-10-15 question 3 answer3 
     4  2010-10-16 question 4 answer4 

我想算註冊用戶,每天和每天發送的問題和答案的數量。我可以用一個mysql查詢來做到這一點嗎?

結果應該是這樣的:

| regdate | new users | questions sent | answers sent | 
-------------------------------------------------------------- 
2010-10-14  2    2     2 
2010-10-15  1    1     1 
2010-10-16  1    1     1 

回答

0

可能:

SELECT regadte, 
     COUNT(userid) as new_users, 
     COUNT(question) as questions_sent, 
     COUNT(answer) as answers_sent 
FROM table 
GROUP BY regdate; 

我不知道,但因爲,你的意思是「新用戶註冊」或「登錄用戶」?另外,從表中,它看起來像一個用戶發送對每個問題,我懷疑是這樣一個答案......

0

試試這個

 
select regdate,count(userid) as new_users,count(question) as question_sent,count(answer) as answers_sent 
from table_name group by regdate