题解 | #用户每月最后一周的练题数#

用户每月最后一周的练题数

https://www.nowcoder.com/practice/00fa10258481407b9a4b3f9a93703700

select device_id,
    date_format(event_date,'%Y年%m月') as ym,
    count(1) as cnt
from question_practice_detail
where day(event_date)>= day(last_day(event_date))-6 
group by device_id,ym
order by device_id,ym

使用date_format(),last_date函数进行处理

其中last_date()返回对应日期中当月的最后一天;

如last_date(2022-09-08) 返回 2022-09-30

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务