oracle - 每月定期进行数据过滤

标签 oracle hadoop filter hive

我想根据我在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/

相关文章:

c# - 在 ASP.net 的浏览器中显示来自 Oracle 数据库的 PDF

hadoop - oozie - 捕获日期并将其作为配置单元参数传递

android - 我得到一个 StaleDataException

oracle - 使用近操作符 LIKE oracle 上下文索引的 Postgres 全文搜索

sql - 我怎样才能摆脱这个查询中的 'ORA-01489: result of string concatenation is too long' ?

oracle - 在另一个存储过程中定义 Oracle 过程的语法是什么?

hadoop - Hadoop:无法加载本地hadoop库

java - hadoop、map/reduce 输出文件(part-00000)和分布式缓存

android - Delphi Android过滤表区分大小写

c# - List<T> C# 中的 WPF datagrid 过滤器数据绑定(bind) List<T1>