Rank:-assigns A Unique Number For Each Row Starting With 1,except For Rows That Have Duplicate Values,in Which Case The Same Ranking Is Assigned And A Gap Appears In The Sequence For Each Duplicate Ranking. Row_number:-returns A Unique Number For Each Row Starting With 1.for Rows That Have Duplicate Values,numbers Are Arbitarily Assigned. Dense_rank:-assigns A Unique Number For Each Row Starting With 1,except For Rows That Have Duplicate Values ,in Which Case Same Ranking Is Assigned.
Ex #1
========== - select ename,empno ,sum(sal) from emp where deptno=10 group by ename,empno order by ename,empno;
Ex #2
========== -
select ename,empno ,sum(sal) SALARY,
-
rank() over(order by sum (sal) desc) RANK,
-
dense_rank() over(order by sum (sal) desc) SALARY_DENSE,
-
ROW_NUMBER() OVER (order by sum (sal) desc) SALARY_NUMBER
-
from emp
-
where deptno=10
-
group by ename,empno
-
order by ename,empno;
Ex #3
========== - select ename,empno ,sum(sal) SALARY,
-
rank() over (PARTITION BY ENAME order by sum (sal) desc) RANK,
-
dense_rank() over (PARTITION BY ENAME order by sum (sal) desc) SALARY_DENSE,
-
ROW_NUMBER() OVER (PARTITION BY ENAME order by sum (sal) desc) SALARY_NUMBER
-
from emp
-
group by ename,empno
-
order by ename,empno;
Ex #4
========== - select DEPTNO,empno ,sum(sal) SALARY,
-
rank() over (PARTITION BY DEPTNO order by sum (sal) desc) RANK,
-
dense_rank() over (PARTITION BY DEPTNO order by sum (sal) desc) SALARY_DENSE,
-
ROW_NUMBER() OVER (PARTITION BY DEPTNO order by sum (sal) desc) SALARY_NUMBER
-
from emp
-
WHERE DEPTNO=30
-
group by DEPTNO,empno
-
order by DEPTNO,empno;
Ex #5
========== - SELECT
-
MIN(DEPTNO)
-
KEEP (DENSE_RANK FIRST ORDER BY SUM(SAL) DESC) BEST,
-
MIN(DEPTNO)
-
KEEP (DENSE_RANK LAST ORDER BY SUM(SAL) DESC) WORST
-
FROM EMP
-
GROUP BY DEPTNO;
Ex #6
========== - SELECT
-
MIN(DEPTNO)
-
KEEP (DENSE_RANK FIRST ORDER BY SUM(SAL) DESC) MIN_BEST,
-
MAX(DEPTNO)
-
KEEP (DENSE_RANK FIRST ORDER BY SUM(SAL) DESC) MAX_BEST,
-
MIN(DEPTNO)
-
KEEP (DENSE_RANK LAST ORDER BY SUM(SAL) DESC) MIN_WORST,
-
MAX(DEPTNO)
-
KEEP (DENSE_RANK LAST ORDER BY SUM(SAL) DESC) MAX_WORST
-
FROM EMP
-
GROUP BY DEPTNO;
HANDLING NULLS
----------------------------------- -
select DEPTNO,empno ,sum(sal) SALARY,
-
rank() over (order by sum (sal) desc NULLS LAST) RANK
-
from emp group by DEPTNO,empno;
-
0 8548 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Petre Huile |
last post by:
I have designed a site for a client, but they have hired an internet
marketing person to incrase their search engine ranking and traffic.
He wants...
|
by: ED |
last post by:
I currently have vba code that ranks employees based on their average
job time ordered by their region, zone, and job code. I currently
have vba...
|
by: Joseph Bloch |
last post by:
In all the threads on ranking in Access queries, I've not seen
anything that deals with ranking against a subset of the query
results. What I need...
|
by: Jeff Boes |
last post by:
I hope this helps someone else ... I had struggled some time ago with
attempts to get a rank of values query to work, but then I gave up and
set it...
|
by: valglad |
last post by:
Hi,
The question below was posted about 4 years ago and noone was able to
answer it back then. I have virtually the same type of problem so would...
|
by: sara |
last post by:
I hope someone can help with this.
Our director wants to have a report that will have the departments
(Retail stores) across the top, stores down...
|
by: AnndieMac |
last post by:
I have an Access 2002 database of inventory count results, and I have been asked to create summaries of the items with the most losses at a store,...
|
by: Chris |
last post by:
I was wodering if there was a way to rank numbers in a query like this
#'s Rank
100 1
99 2
98 3
98
97 5
96 6
96
|
by: Maciej Gawinecki |
last post by:
Hello,
Recently I've interested in quering XML document streams. They can be
queried in keyword- based manner (non-structural queries), as the...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| |