473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Rank records automatically

max
Let's say I have a table with the following fields. State, Customer,
and Total Sales. What I want to do is rank each customer by sales
volume by state. i.e. highest sales is ranked 1, second highest ranked
2, etc within each state.

I think I could do this in a cumbersome fashion by using the max
function, appending, deleting and using the max function again for #2
and so on. I was wondering if there is a built in function or a piece
of code or expression that would assign these rankings automatically in
a new field.

Which brings me to this. I guess I need to learn SQL. Are there any
web resources or books that anyone can recommend? Thanks

max

Oct 7 '06 #1
3 6535
max wrote:
Let's say I have a table with the following fields. State, Customer,
and Total Sales. What I want to do is rank each customer by sales
volume by state. i.e. highest sales is ranked 1, second highest ranked
2, etc within each state.

I think I could do this in a cumbersome fashion by using the max
function, appending, deleting and using the max function again for #2
and so on. I was wondering if there is a built in function or a piece
of code or expression that would assign these rankings automatically in
a new field.

Which brings me to this. I guess I need to learn SQL. Are there any
web resources or books that anyone can recommend? Thanks

max
I created a Continuous form on an employee table query. The two fields
to be displayed were EmployeeID and EmployeeName

I then added a new field. I gave it the name PosIt. It displays the
number as to the rank. In the ControlSource under the datatab I used
=GetPos([EmployeeID])

This calls the function GetPos. This is the code
Private Function GetPos(lngID As Long) As Long
Dim rst As Recordset
Set rst = Me.RecordsetClone
rst.FindFirst "EmployeeID = " & lngID
GetPos = Me.RecordsetClone.AbsolutePosition + 1
rst.Close
Set rst = Nothing
End Function

Would something similar work OK for you? You'd need to modify the above
code and pass the customerID and State (in case the same customer is in
multiple states) to the function.

Oct 8 '06 #2
max wrote:
Let's say I have a table with the following fields. State, Customer,
and Total Sales.
Do yourself a big favor and use only alphanumerics and the underscore for
names. Use the caption property to display something different for the user.
You avoid a lot of bugs that way.
What I want to do is rank each customer by sales
volume by state. i.e. highest sales is ranked 1, second highest ranked
2, etc within each state.
To rank records per group (State), use a correlated subquery:

SELECT (SELECT COUNT(*) + 1
FROM tblCustSales AS C
WHERE (C.State = CS.State AND C.TotalSales CS.TotalSales)) AS RankInState,

CS.State, CS.Customer, CS.TotalSales
FROM tblCustSales AS CS
ORDER BY CS.State, CS.TotalSales DESC;
I guess I need to learn SQL.
Yes, you do if you want to work with relational data to answer questions that
are more complex than can be designed with the QBE grid.
Are there any
web resources or books that anyone can recommend?
Web tutorials will give you the basics, but they don't teach you enough. You
need a book (or a few). "SQL Queries for Mere Mortals" by Michael Hernandez
and John Viescas is a good start.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200610/1

Oct 8 '06 #3
max
Thanks for your help. I ordered the book you recommended. Most
everything I do involves queries, so I guess it is long overdue to
learn SQL.
Granny Spitz via AccessMonster.com wrote:
max wrote:
Let's say I have a table with the following fields. State, Customer,
and Total Sales.

Do yourself a big favor and use only alphanumerics and the underscore for
names. Use the caption property to display something different for the user.
You avoid a lot of bugs that way.
What I want to do is rank each customer by sales
volume by state. i.e. highest sales is ranked 1, second highest ranked
2, etc within each state.

To rank records per group (State), use a correlated subquery:

SELECT (SELECT COUNT(*) + 1
FROM tblCustSales AS C
WHERE (C.State = CS.State AND C.TotalSales CS.TotalSales)) AS RankInState,

CS.State, CS.Customer, CS.TotalSales
FROM tblCustSales AS CS
ORDER BY CS.State, CS.TotalSales DESC;
I guess I need to learn SQL.

Yes, you do if you want to work with relational data to answer questions that
are more complex than can be designed with the QBE grid.
Are there any
web resources or books that anyone can recommend?

Web tutorials will give you the basics, but they don't teach you enough. You
need a book (or a few). "SQL Queries for Mere Mortals" by Michael Hernandez
and John Viescas is a good start.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200610/1
Oct 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Can | last post by:
I am creating an on-line survey. I want the user to have a list of choices of say 10 items that are radio buttons. They need to rank their preference. They click on preference 1, that option is...
3
by: bughunter | last post by:
I discover next problem I have view definition with rank() create view vTEST as select c1, c2, c3, ... -- problem area start , rank() over (order by c3) as RNK -- problem area stop from...
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
2
by: dam_fool_2003 | last post by:
Just now I asked a question about signed char and unsigned char. I had the replay very fast by jens.torring and Tim prince. I post via google so now goes my thanking replay. (I must be more precise...
13
by: Steve Edwards | last post by:
Hi, Given a map: typedef map<long, string, greater<long> > mapOfFreq; Is there a quicker way to find the rank (i.e. index) of the elememt that has the long value of x? At the moment I'm...
1
by: volunteer | last post by:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="filename.xsl"?> <markers date="20060523"> 04:21:50 PM <marker sn="1" rank="6" name="john" /> <marker sn="2" rank="5"...
2
by: orenlevy1 | last post by:
Hi Everyone. I have a problem that I could not figure out what to do with it. I have a couple of tables and views. All have the same unique ID. When a user try to do a search on our web site...
0
by: shilpa.vastrad | last post by:
how to calculate rank in selected records in sql server 2000
6
by: canabatz | last post by:
Hello . i got a list of user with ranking . i want to display the first five places where it is not the same user, like that john : is rank 1 john john david : is rank 2 albert : is rank 3...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.