题解 | #计算用户8月每天的练题数量# 关于时间的函数
计算用户8月每天的练题数量
https://www.nowcoder.com/practice/847373e2fe8d47b4a2c294bdb5bda8b6
正确题解:
select day(date) as day, #day() count(question_id) as question_cnt from question_practice_detail where year(date)=2021 and month(date)=8 #year(),month() group by date
限定条件:2021年8月,写法有很多种,比如用year/month函数的year(date)=2021 and month(date)=8
,比如用date_format函数的date_format(date, "%Y-%m")="202108"
学会了一个新东西 关于时间的函数
比如date的格式是1998-02-03
day(date), month(date), year(date) 返回的是日期中的某天、某月或某年
示例1:select day('1998-02-03')
output:3
学习:https://vimsky.com/examples/usage/day-function-in-mysql.html