累积不同的计数SQL CTools(Pentaho)

时间:2017-12-19 15:29:41

标签: sql count db2 distinct pentaho-ctools

我正在尝试返回一个列,该列计算每行的累计不同用户数(例如,对于一行,您计算从该日期开始回到第一个日期/行的不同用户)。当我在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)

0 个答案:

没有答案