473,511 Members | 16,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running a Query to Establish Rank Based on Points Value

11 New Member
I have a query which calculates the data from two table and then yields the number of points based on various calculations for each category.

Essentially we are trying to rank our Agents based on performance, and each category (Senority, Sales, occurances etc) has a points value. We have a final query that combines all these points values for the different categories to yeild the final total.

What I need is a query that will show the rank of the Agent based on this points value, but gives the same value if a tie is in place.

I have Agent Name as one field in the query and Total Points as the other. I would need a third field Rank, and the only thing I could find was:
Expand|Select|Wrap|Line Numbers
  1. Seniority: (Select Count(*) from Employees Where [HireDate] < _ 
  2.    [Emp1].[HireDate]+1;)
Which is an example given on Microsoft help, but I played with it and still have no idea what to change to give the correct result, it gives me the Syntax error. I was hoping someone could point me in the right direction.

Thanks.
Stephanie
May 6 '08 #1
6 2539
NeoPa
32,557 Recognized Expert Moderator MVP
What is the data you're trying to work with?
Which fields do you have?
Is the recordset you're working from a table or a query (If query, please post the query's SQL)?
May 7 '08 #2
sstidham
11 New Member
The query we want the ranking to be in is:
Expand|Select|Wrap|Line Numbers
  1. SELECT [AGENT NAME],
  2.        Sum([Occurance Score]+
  3.            [Adherence]+
  4.            [EQAMS]+
  5.            [Survey Score]) AS [Total Points]
  6. FROM Test3
  7. GROUP BY [AGENT NAME];
The query it is pulling data from is:
Expand|Select|Wrap|Line Numbers
  1. SELECT [AGENT NAME],
  2.        25-(25*[OCC]/10) AS [Occurance Score],
  3.        [ADH]*20 AS Adherence,
  4.        ([QASCORE]/100)*5 AS EQAMS,
  5.        ([TOTLSC POST]/100)*25 AS [Survey Score]
  6. FROM FlatFileData
  7. GROUP BY [AGENT NAME],
  8.          [OCC],
  9.          [ADH],
  10.          [QASCORE],
  11.          [TOTLSC POST];
Hope this helps.
May 8 '08 #3
NeoPa
32,557 Recognized Expert Moderator MVP
Try the following then. It produces a field using a sub-query (lines #6-8).
Expand|Select|Wrap|Line Numbers
  1. SELECT [AGENT NAME],
  2.        Sum([Occurance Score]+
  3.            [Adherence]+
  4.            [EQAMS]+
  5.            [Survey Score]) AS [Total Points],
  6.        (SELECT Count(*)
  7.         FROM Test3 AS iT3
  8.         WHERE iT3.[AGENT NAME]=oT3.[AGENT NAME])+1 AS [Pos]
  9. FROM Test3 AS oT3
  10. GROUP BY [AGENT NAME]
May 8 '08 #4
sstidham
11 New Member
That seems to be working, however, it is giving everyone the same rank even though the totals value is different. Everyone is getting rank 2 if I leave the +1 and then if I remove it everyone is getting plus 1.

Thank you so much. I hate to be such a bother
May 17 '08 #5
NeoPa
32,557 Recognized Expert Moderator MVP
That'll be because I SNAFUed. Sorry (and it's no bother - I'd far rather you told me than leave any wrong code up - ESPECIALLY if it's mine).
May 19 '08 #6
NeoPa
32,557 Recognized Expert Moderator MVP
As before, but the "=" from line #8 is replaced by a "<".
Expand|Select|Wrap|Line Numbers
  1. SELECT [AGENT NAME],
  2.        Sum([Occurance Score]+
  3.            [Adherence]+
  4.            [EQAMS]+
  5.            [Survey Score]) AS [Total Points],
  6.        (SELECT Count(*)
  7.         FROM Test3 AS iT3
  8.         WHERE iT3.[AGENT NAME]<oT3.[AGENT NAME])+1 AS [Pos]
  9. FROM Test3 AS oT3
  10. GROUP BY [AGENT NAME]
May 19 '08 #7

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

Similar topics

4
10213
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
6
4345
by: Toucan | last post by:
i need to retrieve the most recent timestamped records with unique names (see working query below) what i'm having trouble with is returning the next-most-recent records (records w/ id 1 and 3...
4
2643
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
2
2454
by: RBohannon | last post by:
I'm using Access 2000 on Windows 2000. I have a DB of several exams and people who have taken them. I need to assign ranks to the people according to their scores (within each exam). I have...
0
7897
by: Jeff Boes | last post by:
I hope this helps someone else ... I had struggled some time ago with attempts to get a rank of values query to work, but then I gave up and set it aside. I had another reason to attack it, and in...
5
10890
by: valglad | last post by:
Hi, The question below was posted about 4 years ago and noone was able to answer it back then. I have virtually the same type of problem so would appreciate if anyone can help. Thanks ...
6
3793
by: sara | last post by:
I hope someone can help with this. Our director wants to have a report that will have the departments (Retail stores) across the top, stores down the side and the RANKING of the YTD dept sales...
2
7861
by: jmoore1999 | last post by:
I need to write a t-sql query that will take the value of the previous record into consideration before calculating the current row's new column value... Here's the situation... I have a...
1
1587
by: HSXWillH | last post by:
I hope my question here is clear. I have a table GovVotes that contains the following fields: Year/State/ElectionType/Candidate/Party/PopularVotes. Via net-searching, I found a code for a query...
0
7242
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
7138
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...
1
7081
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
7510
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
5668
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,...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.