我想查看谁是所有活跃用户(所有用户都是最近7天登录)以及所有用户都是非活动用户(过去7天内没有登录)。我有2个表用户和代理商。用户的表结构如下:
id | first_name | email | agency_id | last_login
__________________________________________________
1 Sujith suj@suj 19865 2018/03/01
2 Naveen nav@nav 15098 2018/02/09
3 Salin sal@sal 18452 2017/12/06
代理商的表格结构如下:
id | first_name | email | name | last_login
_________________________________________________________________
19865 Sujith suj@suj Yatra Travels 2018/03/01
19865 Raghav rag@rag Yatra Travels 2018/02/09
15098 Naveen nav@nav Travels Ltd 2017/12/06
15098 Monika mon@mon Travels Ltd 2017/12/06
18452 Raghu rag@rag MK Travels
解释是用户表包含主要代理商详细信息和代理商表包含为代理商工作的员工。因此查询必须检查哪些代理商已登录7天(活动用户)以及哪些代理商已登录7天(非活动用户)。我为Active Users编写了一个查询。我需要重新检查它是否是正确的查询。以及如何为未登录7天或last_login IS NULL的非活动用户编写查询
SELECT users.first_name, users.email, users.last_name, users.last_login, agencies.name,
agencies.id as agencyid FROM users INNER JOIN agencies ON users.agency_id=agencies.id
where users.last_login between adddate(now(),-7) and now() group by agencies.name
order by agencies.name
请有人帮我解决?提前完成。
答案 0 :(得分:1)
new DistanceAsyncTask((TaskListener) getTargetFragment()).execute(result.getData().getCheckin_lat() + "," + result.getData().getCheckin_long(), result.getData().getCompanybranch_lat() + "," + result.getData().getCompanybranch_long());

答案 1 :(得分:-1)
尝试以下查询活跃用户
SELECT users.first_name, users.email, users.last_name, users.last_login, agencies.name, agencies.id as agencyid FROM users INNER JOIN agencies ON users.agency_id=agencies.id where users.last_login between SUBDATE(now(),interval 7 DAY) and now() group by agencies.name order by agencies.name
和非活动用户
SELECT users.first_name, users.email, users.last_name, users.last_login, agencies.name, agencies.id as agencyid FROM users INNER JOIN agencies ON users.agency_id=agencies.id where (users.last_login < SUBDATE(now(),interval 7 DAY) or users.last_login is null) group by agencies.name order by agencies.name