CREATE TABLE #FACT("Yearr" INT,"Monthh" INT, "Acc" varcha...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Philosophy Meta

Q&A about the site for those interested in the study of the fundamental nature of knowledge, reality, and existence

CREATE TABLE #FACT("Yearr" INT,"Monthh" INT, "Acc" varchar(5));
INSERT INTO #FACT
    values 
        (2015, 1, 'A'),
        (2015, 1, 'B'),
        (2015, 1, 'B'),
        (2015, 1, 'C'),
        (2015, 2, 'D'),
        (2015, 2, 'E'),
        (2015, 3, 'E'),
        (2016, 1, 'A'),
        (2016, 1, 'A'),
        (2016, 2, 'B'),
        (2016, 2, 'C');


;with cte
as
(select yearr,monthh,count( distinct acc) as cnt  from #fact
group by yearr,monthh
)
select yearr,monthh,
sum(cnt) over (order by yearr,monthh rows  unbounded preceding ) as x
from cte

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results