我想根据我在Hive或oracle中的要求过滤数据
person month number_of_visits
a 1 12
a 2 10
a 3 20
a 4 10
b 1 12
b 3 15
b 4 12
c 1 10
c 3 18
d 1 14
d 2 18
d 3 26
d 4 34
d 5 36
我的输出要求是:
我想过滤每月定期访问购物中心的人。
如果我考虑4个月的人,则只需要,和以及
因为我可以看到他们1,2,3,4个月的数据。
我无法满足此要求。
擅长查询的人可以帮助我吗?
最佳答案
选择访问时间超过4个月的人员:
select person
from table
group by person
having count(distinct month) >=4
要计算连续访问的难度。让我们找到至少连续访问4次但仅连续访问的人(这比您的问题容易)。
select person
from table
group by person
having count(distinct month) >=4
and min(month) = 1
and max(month) - min(month) = count(distinct month) - 1
如果指定开始月份和结束月份,则可以使用以上查询来解决问题。
关于oracle - 每月定期进行数据过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34046262/