Mysql统计id查询

发布于 2024-09-28 01:04:44 字数 731 浏览 2 评论 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

I'm using mysql table like this one:

|  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

I want to count registered users per day and the number of questions and answers sent per day. Can I do it with one mysql query and how?

The result should be something like:

|  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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

殊姿 2024-10-05 01:04:44

也许:

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

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

maybe:

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

I am not sure though because, do you mean "newly registered users" or "logged in users" ? Also, from your table, it looks like a user has to send an answer for each question, which I doubt is the case...

私野 2024-10-05 01:04:44

试试这个

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

Try this

select regdate,count(userid) as new_users,count(question) as question_sent,count(answer) as answers_sent
from table_name group by regdate
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文