【难度】:简单
【场景】:日人均回答量
【分类】:分组查询、日期函数
分析思路
难点:
1.回答问题数量不去重;答题人数去重
(1)统计11月份日人均回答量(回答问题数量/答题人数),按回答日期排序
注:进入是增加一个在线人数,出去是减少一个在线人数
-
[条件]:month(answer_date) = 11
-
[使用]:count(); month()
最终结果
select 查询结果 [创作日期;日人均回答量]
from 从哪张表中查询数据 [创作者回答情况表]
where 查询条件 [11月份]
group by 分组条件 [创作日期]
order by 对查询结果排序 [创作日期];
求解代码
方法一
case when
select
answer_date,
round(count(issue_id)/count(distinct author_id),2) as per_num
from answer_tb
where month(answer_date) = 11
group by answer_date
order by answer_date