Results 1 to 2 of 2
  1. #1
    mabughazza is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2015
    Posts
    1

    Post select team based on max record .. query


    hi ..

    I built this query :
    Code:
    SELECT X.team AS Winner_team_round, Max(X.SumOfPOINTS) AS MaxOfSumOfPOINTS
    FROM (SELECT Sum(Rounds_points.POINTS) AS SumOfPOINTS, Sum(Rounds_points.VALUES) AS SumOfVALUES, Sum(Rounds_points.TOTAL) AS SumOfTOTAL, Rounds_points.R_ID, Instructors.team, Sum(Rounds_points.SCIENCE) AS SumOfSCIENCE, Sum(Rounds_points.GOLD) AS SumOfGOLD, Sum(Rounds_points.CHALLENGE) AS SumOfCHALLENGE FROM Instructors INNER JOIN Rounds_points ON Instructors.[I_ID] = Rounds_points.[I_ID] GROUP BY Rounds_points.R_ID, Instructors.team HAVING ((((Instructors.team) Like "blue" OR (Instructors.team) Like "red" OR (Instructors.team) Like "yellow" OR (Instructors.team) Like "green")) AND (Rounds_points.R_ID) Like "1" ) ORDER BY Rounds_points.R_ID)  AS X
    GROUP BY X.team;

    and the result is :
    Click image for larger version. 

Name:	11.jpg 
Views:	8 
Size:	13.2 KB 
ID:	22584

    I want to return only RED (WHICH IS THE MAX) ..

    I already succeed to return only 240 by using this :

    Code:
    SELECT Max(X.SumOfPOINTS) AS MaxOfSumOfPOINTSFROM (SELECT Sum(Rounds_points.POINTS) AS SumOfPOINTS, Sum(Rounds_points.VALUES) AS SumOfVALUES, Sum(Rounds_points.TOTAL) AS SumOfTOTAL, Rounds_points.R_ID, Instructors.team, Sum(Rounds_points.SCIENCE) AS SumOfSCIENCE, Sum(Rounds_points.GOLD) AS SumOfGOLD, Sum(Rounds_points.CHALLENGE) AS SumOfCHALLENGE FROM Instructors INNER JOIN Rounds_points ON Instructors.[I_ID] = Rounds_points.[I_ID] GROUP BY Rounds_points.R_ID, Instructors.team HAVING ((((Instructors.team) Like "blue" OR (Instructors.team) Like "red" OR (Instructors.team) Like "yellow" OR (Instructors.team) Like "green")) AND (Rounds_points.R_ID) Like "1" ) ORDER BY Rounds_points.R_ID)  AS X;
    but I want return RED not the 240 ..

    any one can help ???

    another thing I want to save the result in public string too using VBA .. SO I can do some more coding on it ..

    thanks in advance ...

  2. #2
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    sort by maxsumofpoints in descending order, then choose top 1 record.
    You can turn off 'show' if you don't want to see 240.
    To get the value in VBA, open the query in VBA as a recordset and you first (and only) record will be the one you want.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 32
    Last Post: 05-23-2013, 04:16 PM
  2. Replies: 3
    Last Post: 01-24-2013, 08:16 PM
  3. Select record based on values of other records
    By dchaboya in forum Queries
    Replies: 2
    Last Post: 08-11-2011, 10:41 AM
  4. Select based on Max Query
    By eww in forum Queries
    Replies: 2
    Last Post: 05-13-2011, 01:11 PM
  5. Select a certain field of a record based on ID
    By cesarone82 in forum Access
    Replies: 3
    Last Post: 06-06-2009, 01:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums