Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2007

Tip: Looking for answers? Try searching our database.

Rank query help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
weazer - 06 Nov 2007 21:52 GMT
Below is the SQL for a query that I have. Below the SQL is the results. What
I need to do is rank the score by each name in descending order. When the
name changes I need the rank to start at 1 again.  

Thanks in advance for your help. I am stuck.

SELECT [Plant].Name, [Plant].DefectCode, [Plant].Score
FROM [Plant]
GROUP BY [Plant].Name, [Plant].DefectCode, [Plant].Score
ORDER BY [Plant].Name, [Plant].Score DESC;

Name            DefectCode    Score   
Plant A 2000 Widget     100        8
Plant A 2000 Widget    105        5
Plant A 2000 Widget    106        4
Plant A 2001 Widget    105        4
Plant A 2001 Widget    102        3
Plant A 2001 widget    157        2
Plant B 2000 Widget    105        10
Plant B 2000 widget    100        8
Plant B 2000 widget    120        3
Plant B 2001 widget    100        11
Plant B 2001 widget    110        10
Plant B 2001 widget    107        7
Plant C 1999 widget    100        8
Plant C 1999 widget    110        5
Plant C 1999 widget    120        4
Plant C 2004 widget    111        5
Plant C 2004 widget    111        5
Plant C 2004 widget    111        5
KARL DEWEY - 06 Nov 2007 23:50 GMT
Try this --
SELECT Q.Name, Q.DefectCode, Q.Score, (SELECT COUNT(*) FROM Plant Q1
     WHERE Q1.[Name] = Q.[Name]
       AND Q1.Score > Q.Score)+1 AS Rank
FROM Plant AS Q
ORDER BY Q.Name, Q.Score DESC;

Signature

KARL DEWEY
Build a little - Test a little

> Below is the SQL for a query that I have. Below the SQL is the results. What
> I need to do is rank the score by each name in descending order. When the
[quoted text clipped - 26 lines]
> Plant C 2004 widget    111        5
> Plant C 2004 widget    111        5
weazer - 08 Nov 2007 00:51 GMT
Thanks for the reply. When I ran this SQL it gave me a syntax error with the
following:

>SELECT Q.Name, Q.DefectCode, Q.Score, (SELECT COUNT(*) FROM Plant Q1
>      WHERE Q1.[Name] = Q.[Name]
>        AND Q1.Score > Q.Score)+1

Everything I tried did not correct the error.

Please le me know if you see where the syntax error is.

Thanks again.

>Try this --
>SELECT Q.Name, Q.DefectCode, Q.Score, (SELECT COUNT(*) FROM Plant Q1
[quoted text clipped - 8 lines]
>> Plant C 2004 widget    111        5
>> Plant C 2004 widget    111        5
Smartin - 10 Nov 2007 22:58 GMT
> Thanks for the reply. When I ran this SQL it gave me a syntax error with the
> following:
[quoted text clipped - 24 lines]
> --
> Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200711/1

Prolly needs a closing paren before "AS Rank":

SELECT Q.Name, Q.DefectCode, Q.Score, (SELECT COUNT(*) FROM Plant Q1
     WHERE Q1.[Name] = Q.[Name]
       AND Q1.Score > Q.Score)+1 ) AS Rank
FROM Plant AS Q
ORDER BY Q.Name, Q.Score DESC;
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.