2010-10-17 81 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