我目前正在使用以下查询;
ROUND(SUM(cost)/1e6) as val
FROM adcube dac
WHERE adverwith t as (
SELECT advertisable, EXTRACT(YEAR from day) as yy, EXTRACT(MONTH from day) as mon,
tisable_eid IN (SELECT advertisable
FROM adcube dac
GROUP BY advertisable
HAVING SUM(cost)/1e6 > 100
)
GROUP BY advertisable, EXTRACT(YEAR from day), EXTRACT(MONTH from day)
)
select advertisable, min(yy * 10000 + mon) as yyyymm
from (select t.*,
(row_number() over (partition by advertisable order by yy, mon) -
row_number() over (partition by advertisable, val order by yy, mon)
) as grp
from t
)
group by advertisable, grp, val
having count(*) >= 4 and val = 0
这为我提供了可广告停止的月份和年份,以及=> = 4个月的= 0。 是否有可能在最后插入一个额外的查询,以便4个计数的值为0的可广告,但在4之后再次花费?即跟踪可重新激活广告的月份?
的后续行动