我在Netezza中有一个这样的查询,但不确定如何重写它才能工作。感谢
with dates as (
select distinct event_date from table
)
select event_date,
(select count(distinct id)
from table
where event_date < dates.event_date
)
from dates
This form of correlated query is not supported - consider rewriting
无论如何,使用窗口函数会更高效。我认为逻辑是:
select event_date,
sum(count(*)) over (order by event_date) - count(*) as events_before
from table
group by event_date