473,396 Members | 2,036 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,396 software developers and data experts.

Rank in Sequential Order - MS Access 2003

Hi all,
I am a just starting to build my own formula's and limited skills w/ writing sql.

I am having some issues trying to rank by an id and based on the rate of a particular procedure, we reimburse the top 3 highest charge_amt in the following levels... i.e. highest procedure 1 is payed @ 100%, procedure 2 @ 50% and procedure 3 @ 25%.

Unfortunately my data is not in sequential order by charge_amt, so I was trying to run a query only pulling the ID and sorted Charge_amt Desc order, now I need to rank the top 3, then multiply according to the procedure #. I tried count function, but I am obviously missing a step along the way.

Any tips and/or help would be greatly appreciated!

Thanks,
Shana
May 19 '08 #1
3 2665
NeoPa
32,556 Expert Mod 16PB
This will be hard but not impossible to do in a single set of SQL using subqueries.
Much easier to save the subquery as a QueryDef (saved query).

Start off by creating a QueryDef in Access called [qryTop3] with the following SQL.
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 3 [ID],
  2.              [Charge_Amt]
  3. FROM [YourTable]
  4. ORDER BY [Charge_Amt] DESC
With that query now generally available the following SQL should do the trick for you :
Expand|Select|Wrap|Line Numbers
  1. SELECT [ID],
  2.        [Charge_Amt],
  3.        (SELECT Count (*)
  4.         FROM [qryTop3] AS [iTop3]
  5.         WHERE iTop3.Charge_Amt>oTop3.Charge_Amt) AS [Ordinal],
  6.        [Charge_Amt]*(4-IIf([Ordinal]=0,0,[Ordinal]+1))/4 AS [Reimburse]
  7. FROM [qryTop3] AS [oTop3]
  8. ORDER BY [Charge_Amt] DESC
Clearly you can use whatever names suit you best for your queries, and I suspect you'll need to rename [YourTable] too.
May 19 '08 #2
Hi Neopa,
Thanks for your reply, although I apologize. I wasn't very clear on my results I was needing. When I ran your first query all it pulled was the top 3 for my whole data set, but I actually the top 3 per id. I tried to manipulate the code, but could get it to pull the top 3 for each id. Your assistance is greatly appreciated:)

Example:
abc $400
abc $750
abc $250
xyz $550
xyz $750
xyz $800

What I need is:
abc $750 1 - will mutliply by 1
abc $400 2 - will mutilply by .5
abc $250 3 - will muptiply by .25
xyz $800 1 - will mutliply by 1
xyz $750 2 - will multiply by 2
xyz $550 3 - will multiply by 3
May 20 '08 #3
NeoPa
32,556 Expert Mod 16PB
Why don't you start by posting what you DID try?
May 20 '08 #4

Sign in to post your reply or Sign up for a free account.

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...
3
by: j0mbolar | last post by:
what's the rules of rank and how they affect types of expressions?
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"...
3
by: jim_geissman | last post by:
I would like to write a query that gives me the values of a set of observations, and their rank. CREATE TABLE #Values(val int) INSERT #Values SELECT 1 INSERT #Values SELECT 5 INSERT #Values...
3
by: Helge's | last post by:
I have this sql that give me the sales rank from the highest to the lowest. I have several categories and need to rank within each category. h1.Cat is the categoryfield. SELECT h1.Cat, h1.Oms,...
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...
11
by: Timofmars | last post by:
I'm try to Unload DB2 data from a table into a record sequential file on NT. I can an unload on Mainframe, but it doesn't seem to be an option in NT. In NT, all I can do is export/import. I can...
9
by: Axxe | last post by:
I have searched high and low for cogent, well-explained coding to complete a project on which I have spent six months of work. I stumbled across something on this site that is close to what I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.