1

我正在尝试返回一个列,该列计算每一行的用户累积不同计数(即,对于一行,您正在计算从该日期移回第一个日期/行的不同用户)。当我在 DB2 中运行此查询时,我得到“无效使用关键字 DISTINCT”。

关于如何将其转换为有效查询以返回用户名的累积不同计数的任何想法?

select title, "Date", th as "Total Monthly Hits", 
sum(th) over (partition by pageid order by "Date") as "Cumulative Total Hits", tuh as "Unique Monthly Hits", 
count(distinct(username)) over (partition by pageid order by "Date") as "Cumulative Total Unique Hits"  from(
select pageid, username, title, ym as "Date", sum(h) as th, sum(uh) as tuh from (
            select pageid, username
            ,NVL((select c.agest from COMMON.VMAX300A_AGENCY_USER c where c.ldap_email=d.username),'Unknown') as agency
            ,title, ym, h, uh from (
                        select pageid, username, title, ym, sum(hits) as h, count(distinct(username)) as uh from (
                                    select PAGEID,a.username
                                    ,(select MAX(b.TITLE) from bfelob_etl.budget_page_hits b where b.PAGEID=a.PAGEID) as title
                                    ,substr(SHORT_DATE,1,7) as ym,
                                    hits
                                    from bfelob_etl.budget_page_hits a
                                    where PAGEID in (1503)
                        ) group by pageid, username, title, ym 
            ) d
) group by pageid, username, title, ym)
where PAGEID in (1503)
4

0 回答 0