sql - SQL 查询 - 选择值出现 25 次以上的结果记录
问题描述
我有以下查询正常工作:
select o.SubscriberKey , o.JobID, CAST(o.EventDate AS Date) AS 'OpenDate'
FROM _Open o
where o.IsUnique = 1 and (o.EventDate between 'Jun 06 2018' and 'Dec 06 2018')
GROUP BY o.SubscriberKey , o.JobID, o.EventDate
现在我需要将其修改为仅选择在结果中出现 25 次或更多的订阅者密钥。我想我可以使用 Count 函数,但我不确定从那里去哪里。
解决方案
使用窗口函数:
select o.*
from (select o.SubscriberKey, o.JobID, CAST(o.EventDate AS Date) AS OpenDate,
count(*) over (partition by o.SubscriberKey) as cnt
from _Open o
where o.IsUnique = 1 and (o.EventDate between 'Jun 06 2018' and 'Dec 06 2018')
group by o.SubscriberKey, o.JobID, o.EventDate
) o
where cnt >= 25
推荐阅读
- c# - 插值字符串格式问题
- angular - router-outlet 正在附加而不是替换 Angular 6.0.3
- opencv - 关于 RGB 和 CIELAB 之间转换的说明
- javascript - 这个增量重试代码是如何工作的?
- python - 舍入函数不是舍入?
- google-apps-script - 在 Google 表格中,使用脚本从图像中创建可点击的超链接
- apache-kafka - kafka 流 ktable 数据丢失
- c# - 使用 PostgreSQL 在 LINQ C# 上按列获取最后一行分组
- python - 如何在视图中使用 django 对象
- php - php中的setcookie函数和phpinfo不工作但在localhost工作