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

How Do I Make a Rank Query wih Multiple Criteria?

31
Hi All,


I am working on a ranking Items in a query and I am stuck when I need to take more fields into account for the rank.


Currently I have a query that ranks [Location] by the [Date] they were entered for each [Item]. We have multiple locations for each item so the earliest date gets ranked 1 for each [Item]


The SQL below works pretty well so far:

Expand|Select|Wrap|Line Numbers
  1. SELECT a.Company, a.Item, a.Location, a.Status, a.Date, Count(*) AS Rank
  2. FROM (SELECT Company, Item, Location, Status, Date 
  3. FROM qrySKULocation02 
  4. GROUP BY Company, Item, Location, Status, Date
  5. )  AS a INNER JOIN (SELECT Company, Item, Location, Status, Date 
  6. FROM qrySKULocation02 
  7. GROUP BY Company, Item, Location, Status, Date
  8. )  AS b ON (a.Item = b.Item) AND (a.Date >= b.Date)
  9. GROUP BY a.Company, a.Item, a.Location, a.Status, a.Date
  10. ORDER BY a.Company, a.Item, a.Date, Count(*);
  11.  

But I need to expand the query and I would like to assign a rank number for each Item taking [Status] into account first, and then by [Date], and then by [Location]


Hopefully that was clear enough and someone can help me out.

Thanks in advance.
Dec 11 '13 #1
1 3896
zmbd
5,501 Expert Mod 4TB
I don't rank very often, and rarely on anything other than one field.

However, from what I remember you will need a series of union queries to tie all of your fields into one, and then do the ranking query against this new union.
just a general tip on ranking Allen Browne's Ranking Tutorial

Personally, when I end up having to create a ranking query, it's usually, but not always (IMHO), because I've not normalized the database properly; thus, it's worth a look to see if you can normalize the table structure a bit more!
Dec 11 '13 #2

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

Similar topics

4
by: ShyGuy | last post by:
I have a table with 4 fields. Three are used for criteria. I can get the DLookup to work with 1 criteria with the following but can't get it to work with 2 or three. NumofAppts = DLookup("",...
0
by: Greg Strong | last post by:
Hello All, In the past I've used a combo box with the 'row source' being an Access SQL union query to select "All" or 1 for only 1 criteria in a query. An example is as follows: SELECT 0 As...
3
by: developing | last post by:
Hello How do I specify multiple criteria for FindFirst or FindRecord (or anything else) that takes the criteria from a form. (text field and number field) edit: this will be in the after...
4
by: JHNielson | last post by:
I have a query that I'm trying to update with a dlookup with multiple criteria This is the string: EVNT_DT: DLookUp("","","( .EVNT_QTR=.) & (.=.)") When i run it it says it can't find the...
1
by: Tlou5831 | last post by:
I am attempting to compare 2 tables in my DB and find unmatched criteria. There are 2 different fields in each database that need to be compared. Tbl_AppUsers Role Settings INQ ...
3
by: kstevens | last post by:
Please help. I know the sysntax is wrong. Here are some details. I am looking for the sum of past shipped items. I originally wrote this Dsum with only one criteria, but because of multiple...
1
by: Brendan Wolf | last post by:
Happy Halloween all, I have been struggling at work with a DLookup using multiple criteria. I would like a text box to display the results of a DLookup based on the values selected in three...
3
by: Brendan Wolf | last post by:
Happy Halloween all, I have been struggling at work with a DLookup using multiple criteria. I would like a text box to display the results of a DLookup based on the values selected in three...
4
by: DANNYOCEAN | last post by:
I have a code that sucessfully calculates how many numbers are lower than for example 45 , for large sample number list. But i´m looking for a code that have a COUNT function with MULTIPLE...
3
by: M0ji | last post by:
I have created an update query to auto populate the value of one field based on the value of another field. I have two fields "Level" and "Document" if Document is A, Level needs to be 1 if...
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
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
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
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.