我从PostgreSQL得到了"聚合函数调用不能嵌套"的错误。我尝试了不同的方法,但是未能解决。
select c.*, (
select sum((count(distinct product_id))/2)
from page_views
where product_id in (c.p1, c.p2)
group by user_id, session_id
having count(distinct product_id) > 1
) freq
from (
select a.product_id p1, b.product_id p2
from (select distinct product_id from page_views) a,
(select distinct product_id from page_views ) b
where a.product_id <> b.product_id
) c ;
谢谢!