【问题标题】:Correlated subquery not working in Netezza相关子查询在 Netezza 中不起作用
【发布时间】:2021-03-18 10:46:54
【问题描述】:

我在 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

【问题讨论】:

  • 能否提供一些示例数据和预期结果
  • 如果你解释你想要实现的逻辑也会有帮助。

标签: sql netezza correlated-subquery


【解决方案1】:

无论如何,使用窗口函数会更有效。我认为逻辑是:

select event_date, 
       sum(count(*)) over (order by event_date) - count(*) as events_before
from table
group by event_date

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多