从MySql切换到Vertica,在where子句中聚合无效

从MySql切换到Vertica,在where子句中聚合无效,sql,vertica,Sql,Vertica,最近我们从MySQL切换到Vertica。我不知道如何重新创建您将以这种方式使用子查询。您将使用窗口功能: select count(distinct cr.id) as Cars, count(distinct cp.id) as CarParts from users u join user_emails ue on u.id = ue.user_id join (select cr.*, count(*) over (partition by u

最近我们从MySQL切换到Vertica。我不知道如何重新创建您将以这种方式使用子查询。您将使用窗口功能:

select count(distinct cr.id) as Cars,
       count(distinct cp.id) as CarParts
from users u join
     user_emails ue
     on u.id = ue.user_id join
     (select cr.*, count(*) over (partition by user_id) as cnt
      from cars cr
     ) cr
     on cr.user_id = u.id join
     car_parts cp
     on cp.car_id = cr.id
where cr.cnt <= 30 and
      ue.is_real = true and ue.is_main = true
      cr.created_at >= '2017-01-01' and
      cr.created_at < '2017-02-18';
注:

不要将列别名括在单引号中。这是一个等待发生的错误。仅对字符串和日期常量使用单引号。
您可以简化日期逻辑。使用这个在Vertica不起作用?在什么方面不起作用?老鼠飞走了?显示器关机?让你消化不良?哈哈。抱歉信息不足-我收到以下错误:错误:不支持具有聚合函数计数的相关子查询请下次使用此信息更新问题,而不是提出新的注释,当然,添加评论以表示感谢@Nick.McDermaid,但保留问题中的重要内容。我将为您添加错误。这项工作很棒!我看到分区成功了。。。我需要多读一些这方面的内容才能完全理解它。这让我走上了正确的道路——我真的很感激!你的提示也被及时注意到了
select count(distinct cr.id) as Cars,
       count(distinct cp.id) as CarParts
from users u join
     user_emails ue
     on u.id = ue.user_id join
     (select cr.*, count(*) over (partition by user_id) as cnt
      from cars cr
     ) cr
     on cr.user_id = u.id join
     car_parts cp
     on cp.car_id = cr.id
where cr.cnt <= 30 and
      ue.is_real = true and ue.is_main = true
      cr.created_at >= '2017-01-01' and
      cr.created_at < '2017-02-18';