Skip to content

Commit 8b89cde

Browse files
committed
topn
1 parent 57d86d1 commit 8b89cde

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

optimizer/topn/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Some example Approximate Top-N queries available since Oracle Datatbase 18c.

optimizer/topn/eg1.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ELECT deptno, job, APPROX_SUM(sal),
2+
APPROX_RANK(partition by deptno ORDER BY APPROX_SUM(sal) desc) rk
3+
FROM emp
4+
GROUP BY deptno, job
5+
HAVING APPROX_RANK(partition by deptno ORDER BY APPROX_SUM(sal) desc) <= 10;
6+

optimizer/topn/eg2.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
connect scott/tiger
2+
3+
SELECT deptno, job, APPROX_SUM(sal), APPROX_COUNT(*)
4+
FROM emp
5+
GROUP BY deptno, job
6+
HAVING APPROX_RANK(partition by deptno ORDER BY APPROX_SUM(sal) desc) <= 2
7+
AND APPROX_RANK(partition by deptno ORDER BY APPROX_COUNT(*) desc) <= 3;
8+

optimizer/topn/eg3.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
connect scott/tiger
2+
3+
SELECT deptno, job, APPROX_SUM(sal) sum_sal,
4+
APPROX_SUM(sal,'MAX_ERROR') sum_sal_err
5+
FROM emp
6+
GROUP BY deptno, job
7+
HAVING APPROX_RANK(partition by deptno ORDER BY APPROX_SUM(sal) desc) <= 2;

0 commit comments

Comments
 (0)