Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ranking query

Posted on 2013-12-09
5
Medium Priority
?
300 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 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

604 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