SQL查询-选择值出现25次以上的结果记录

时间:2018-11-28 21:53:16

标签: sql salesforce

我有以下查询正常工作:

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次或更多次的SubscriberKeys。我想我可以使用Count函数,但是我不确定从那里去哪里。

1 个答案:

答案 0 :(得分:0)

使用窗口功能:

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