题意明确:
2021年8月每天用户练习题目的数量
问题分解:
- 限定条件:2021年8月,写法有很多种,比如用year/month函数的
year(date)=2021 and month(date)=8,比如用date_format函数的date_format(date, "%Y-%m")="202108" - 每天:按天分组
group by date - 题目数量:count(question_id)
 
细节问题:
- 表头重命名:as
 - 输出示例中每天的字段只取了几号,要去掉年月,用day函数即可
 
完整代码:
select
    day(date) as day,
    count(question_id) as question_cnt
from question_practice_detail
where month(date)=8 and year(date)=2021
group by date 


京公网安备 11010502036488号