Interview Questions   Tutorials   Discussions   Programs

# Cognos - What is the difference between count and running-count functions?

1043
views
asked mar October 2, 2014 01:30 AM

What is the difference between count and running-count functions?

For each row, this displays the quantity and a running count of the position of current row. COUNT:determine the total number of (a collection of items).

eg.
SELECT deptno,
COUNT(*) DEPT_COUNT
FROM emp
WHERE deptno IN (20, 30)
GROUP BY deptno;

DEPTNO DEPT_COUNT

20 5
30 6

running count:running count of the position of current row Eg

SELECT empno, deptno,
COUNT(*) OVER (PARTITION BY
deptno) DEPT_COUNT
FROM emp
WHERE deptno IN (20, 30);

EMPNO     DEPTNO DEPT_COUNT
7369         20          5
7566         20          5
7788         20          5
7902         20          5
7876         20          5
7499         30          6
7900         30          6
7844         30          6
7698         30          6
7654         30          6
7521         30          6
flag

For each row, this displays the quantity and a running count of the position of current row. COUNT:determine the total number of (a collection of items).

eg.
SELECT deptno,
COUNT(*) DEPT_COUNT
FROM emp
WHERE deptno IN (20, 30)
GROUP BY deptno;

DEPTNO DEPT_COUNT

20 5
30 6

running count:running count of the position of current row Eg

SELECT empno, deptno,
COUNT(*) OVER (PARTITION BY
deptno) DEPT_COUNT
FROM emp
WHERE deptno IN (20, 30);

EMPNO     DEPTNO DEPT_COUNT
7369         20          5
7566         20          5
7788         20          5
7902         20          5
7876         20          5
7499         30          6
7900         30          6
7844         30          6
7698         30          6
7654         30          6
7521         30          6
flag

### Join with account you already have

Preview

Online-Classroom Classes
www.writeabc.com

1 person following this question

1 person following this tag

Question tags

cognos × 1

Asked 1 year and 1 month ago ago
Number of Views -1043