0

我正在使用这样的mysql表:

|  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
4

2 回答 2

0

也许:

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

我不确定,因为您的意思是“新注册用户”还是“登录用户”?此外,从您的表格来看,用户似乎必须为每个问题发送答案,我怀疑是这种情况......

于 2010-10-17T16:58:57.423 回答
0

尝试这个

选择 regdate,count(userid) 作为 new_users,count(question) 作为 question_sent,count(answer) 作为 answers_sent
通过 regdate 从 table_name 组
于 2010-10-17T16:59:27.067 回答