牛客网刷题学习SQL(八)

SQL28 计算用户8月每天的练题数量

牛客网刷题学习SQL(八)_第1张图片
牛客网刷题学习SQL(八)_第2张图片
问题分解:
限定条件: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)

select day(date) day , count(question_id) question_id
from question_practice_detail qpd
where date_format(date,'%Y-%m')='2021-08'
group by day

select day(date) day , count(question_id) question_id
from question_practice_detail qpd
where year(date)=2021 and month(date)=8
group by day

你可能感兴趣的:(JAVA常用SQL,学习,sql,数据库)