56,940
社区成员




SELECT case when cnt <2 then '2次以下'
when cnt <3 then '3次以下'
when cnt <4 then '4次以下'
when cnt <5 then '5次以下'
else '5次以上' end as c, count(*)
from
(select user_ip, count(*) as cnt
from group_table
where create_time > CURDATE() -INTERVAL 7 DAY
GROUP BY user_ip) as t
GROUP BY cnt
select case when cnt<=5 then '5次以下'
when cnt<=10 then '5次~10次'
when cnt<=20 then '10~20次'
else then '200次以'
end as c, count(*)
from (
select user_id, count(*) as cnt
from test
where create_time>CURDATE()-interval 7 day
group by user_id
) t
group by case when cnt<=5 then '5次以下'
when cnt<=10 then '5次~10次'
when cnt<=20 then '10~20次'
else then '200次以'
end
-- 占比
select a/users, b/users, c/users
from(
select -- 用户总数和 3 个区间登录用户数
count(*) as users
, sum(case when data.times < b.a then 1 end) as a
, sum(case when data.times < b.b and data.times >=b.a then 1 end) as b
, sum(case when data.times > b.b then 1 end) as c
from(
-- 每个用户在指定时间段内(周/月/年)的登录次数
select user_id, count(*) as times
from table
where create_time between 'xx' and 'xx' -- **** 统计区间
group by user_id
) data,
(select 10 as a, 50 as b) b -- **** 定义 3 个统计区间: <a, <b and >=a, >b
) xx