题解 | #筛选限定昵称成就值活跃日期的用户#
筛选限定昵称成就值活跃日期的用户
https://www.nowcoder.com/practice/2ed07ff8f67a474d90523b88402e401b
select distinct ui.uid, nick_name, achievement from user_info ui left join exam_record er on ui.uid=er.uid left join practice_record pr on ui.uid = pr.uid where nick_name like '牛客%号' and achievement between 1200 and 2500 and (date_format(er.start_time,'%Y%m') = '202109' or date_format(pr.submit_time,'%Y%m') = '202109'); 日期的判断之间用了or,必须用括号将这两句判断括起来,不然因SQL先判断and,会将满足了or后的条件也筛选出来,结果会多出其他uid。 从表exam_record中筛选出月份是2021年9月提交的用户ID。where date_format(submit_time, '%Y%m') = '202109'