题解 | #筛选限定昵称成就值活跃日期的用户#

筛选限定昵称成就值活跃日期的用户

https://www.nowcoder.com/practice/2ed07ff8f67a474d90523b88402e401b

select uid,nick_name,achievement from user_info
where nick_name like "牛客%号" and achievement between 1200 and 2500
and uid in (
    select uid from exam_record
    where year(start_time)=2021 and month(start_time)=09
    union
    select uid from practice_record
    where year(submit_time)=2021 and month(submit_time)=09
);

题目要求的用户信息均来自user_info表,则按照要求筛选出对应的用户信息即可

1.用户昵称以“牛客”开头“号”结尾,对昵称进行模糊查询,like 条件1: nick_name like "牛客%号" ,其中%表示中间有0-多个字符(不确定),另“_”表示一个字符;

2.成就值在1200-2500之间,between...and 条件2:achievement between 1200 and 2500

3.用户最近一次活跃在2021年9月:(没注意是最近一次,那我这个并不严谨,只是筛选了2021年9月有活跃记录的用户,但结果是通过了的,就。。。)

从表exam_record和 pratice_record中查找符合条件的用户并将结果去重展示:union

uid in (

select uid from exam_record

where year(start_time)=2021 and month(start_time)=09

union

select uid from practice_record

where year(submit_time)=2021 and month(submit_time)=09

全部评论
补一个参考了评论区各位的,满足最近活跃日期在2021年9月的: select uid,nick_name,achievement from user_info where nick_name like "牛客%号" and achievement between 1200 and 2500 and uid in ( select uid from exam_record group by uid having date_format(max(start_time),'%Y%m') = 202109 union select uid from practice_record group by uid having date_format(max(submit_time),'%Y%m')=202109 );
点赞 回复 分享
发布于 2023-01-04 11:49 贵州

相关推荐

不愿透露姓名的神秘牛友
11-16 01:46
点赞 评论 收藏
分享
迷茫的大四🐶:看来已经准备换人了
点赞 评论 收藏
分享
11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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