Solved

ranking query

Posted on 2013-12-09
5
297 Views
Last Modified: 2013-12-09
I have this very simple query here
SELECT distinct
xdate,
store
FROM deldates;

Open in new window


that gives me

XDATE	STORE
2	10411
5	10411
5	10412
2	10412
7	10413
4	10413
6	10414
4	10414
2	10414
6	10415
3	10415
6	10416
3	10416
6	10418
2	10418
4	10427
7	10427
7	10428
4	10428
3	10429

Open in new window


I am looking for a new query that will give these results

XDATE	STORE	RANKING
2	10411	1
5	10411	2
5	10412	2
2	10412	1
7	10413	2
4	10413	1	
6	10414	3
4	10414	2
2	10414	1
6	10415	2
3	10415	1
6	10416	2
3	10416	1
6	10418	2
2	10418	1
4	10427	2
7	10427	1
7	10428	2
4	10428	1
3	10429	1

Open in new window

0
Comment
Question by:FutureDBA-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39707079
Ty this (untested, just typed in):
SELECT distinct
xdate,
store,
rank() over(partition by store order by xdate) myrank
FROM deldates;
0
 

Author Comment

by:FutureDBA-
ID: 39707095
that's on the right track i think, but the results are wrong.

XDATE	STORE	MYRANK
2	1000	1
5	1000	19
3	10395	1
7	10395	12
2	10396	1
5	10396	17
2	10397	1
4	10397	11
6	10397	21
3	10400	1
5	10400	12
7	10400	23
4	10401	1
7	10401	11
2	10402	1
5	10402	23
2	10403	1
5	10403	10
4	10404	1
7	10404	5
3	10405	1
6	10405	12

Open in new window



i added an order by clause to main query to make it easier to work with
SELECT distinct
xdate,
store,
rank() over(partition by store order by xdate) myrank
FROM deldates
order by store, to_number(xdate);
0
 

Author Comment

by:FutureDBA-
ID: 39707108
dense_rank worked
0
 
LVL 18

Expert Comment

by:sventhan
ID: 39707110
try this ..

SELECT distinct
xdate,
store,
rank() over(partition by store,xdate order by store,xdate) myrank
FROM deldates
0
 

Author Closing Comment

by:FutureDBA-
ID: 39707139
set me on right path,

used desne_rank instead of rank.

thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
migration MS SQL database to Oracle 30 71
Oracle DB monitor SW 21 74
Help with Oracle IF statment 5 37
error doing substr 3 38
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question