我的任务是:
导出了创建>=1费用但在创建后7天没有登录应用程序的客户列表(5月3日至9日)
我需要以某种方式创建一个逻辑,以检查用户在创建自己的开销之后是否没有登录,但我在SQL方面几乎是绿色的,所以我不知道这一切是如何工作的。目前,我只创建了一个逻辑,它获取所有用户并检查在时间线(即5月3日至9日)中创建的发票。
如何检查用户是否在7天内没有登录。
select u.*
from users_user u
where u.completed_registration
and exists (
select id
from operation_operation op
where op.company_id = u.active_company_id
)
and exists (
select id
from invoice_invoice inv
right join operation_operation op
on inv.operation_ptr_id = op.id
and op.created_at between '2021-05-03 00:00:00' and '2021-05-09 00:00:00' /*specify the date of the creation (3-9 May) */
group by id having count(*) >= 1
)
/*
How can we check if the user wasn't logged in after the creation for 7days
we use "u.last_login" for our user last online date
*/发布于 2021-05-28 15:02:12
您的查询中有一个错误,让我试着解释一下:
这将使用u.completed_registration选择您的用户。
select u.*
from users_user u
where u.completed_registration一定有一个operation_operation在u.active_company_id注释中:这个operation_operation可能与那个用户无关,它也可能涉及到该公司的另一个用户!
and exists (
select id
from operation_operation op
where op.company_id = u.active_company_id
)而且必须有一个以上的发票,(但这张发票似乎没有对用户的参考?)
and exists (
select id
from invoice_invoice inv
right join operation_operation op
on inv.operation_ptr_id = op.id
and op.created_at between '2021-05-03 00:00:00' and '2021-05-09 00:00:00' /*specify the date of the creation (3-9 May) */
group by id having count(*) >= 1
)https://stackoverflow.com/questions/67739716
复制相似问题