我有一个用户数据库,我需要帮助才能形成查询。
Table = users
fields = sign_in_count , last_sign_in_at
这两个查询给出了以下结果: -
select *
from users
where last_sign_in_at >= '2015-08-01' and sign_in_count != ''
给了我131000行。
select *
from users
where last_sign_in_at between '2015-05-01' and '2015-09-11' and
sign_in_count <> ''
给了我203000行。
因此,在05/15至08/15之间至少登录过一次的72,000名用户中的用户差异。
我需要知道这些不止一次登录的72k用户的用户数。
答案 0 :(得分:0)
如果users
表格有user_id
列,则下面的查询可以正常工作。
select count(user_id) from
(
select user_id --replace it with appropriate user identifier column
from (select * from users
where last_sign_in_at between '2015-05-01' and '2015-09-11'
and sign_in_count != ''
and user_id not in (select user_id from users
where last_sign_in_at >= '2015-08-01' and sign_in_count!='')
) t
group by user_id
having count(*) > 1
) t1
答案 1 :(得分:0)
有什么问题
Select count(*) from users
where last_sign_in_at between '2015-05-01' and '2015-08-01'
and sign_in_count > 1
或者我错过了什么?
答案 2 :(得分:0)
您想要查询已登录多次的所需时间范围内的用户总数。
但您只是要查询“2015-05-01”和“2015-08-01”之间的用户总数以及sign_in_count&lt;&gt; ''。
答案 3 :(得分:0)
考虑在where
的派生表中考虑两个count()
条件的剩余部分:
select count(*)
from
(select * from users
where last_sign_in_at > '2015-05-01'
and last_sign_in_at < '215-08-01'
and sign_in_count != '')