user表
uid,uname
user_log表
log_id,uid,login_time
其中user_log表只记录用户登录的日期。
请问mysql怎么查询本周未登录的用户
eg:
user
uid | uname |
---|---|
1 | uname1 |
2 | uname2 |
user_log
log_id | uid | login_time |
---|---|---|
1 | 1 | 2022-01-01 |
1 | 2 | 2022-01-01 |
2 | 1 | 2022-01-03 |
2 | 2 | 2022-01-03 |
2 | 1 | 2022-01-15 |
user表
uid,uname
user_log表
log_id,uid,login_time
其中user_log表只记录用户登录的日期。
请问mysql怎么查询本周未登录的用户
eg:
user
uid | uname |
---|---|
1 | uname1 |
2 | uname2 |
user_log
log_id | uid | login_time |
---|---|---|
1 | 1 | 2022-01-01 |
1 | 2 | 2022-01-01 |
2 | 1 | 2022-01-03 |
2 | 2 | 2022-01-03 |
2 | 1 | 2022-01-15 |
select * from user where id not in (
select uid from user_log where login_time >= DATE_FORMAT( DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), '%Y-%m-%d')
and login_time <= DATE_FORMAT( DATE_ADD(SUBDATE(CURDATE(), WEEKDAY(CURDATE())), INTERVAL 6 DAY), '%Y-%m-%d')
)
可以试试