Solved

ranking query

Posted on 2013-12-09
5
293 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-
  • 3
5 Comments
 
LVL 76

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now