Results 1 to 2 of 2
  1. #1
    Jackmouve is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Location
    Seattle
    Posts
    1

    Need Query Help

    I have a query that looks like this:



    SELECT VRCRaceRegistrants.PSNID, Sum(VRCRaceRegistrants.Points) AS TotalPoints, VRCRaceRegistrants.RaceYear
    FROM VRCRaceRegistrants
    GROUP BY VRCRaceRegistrants.PSNID, VRCRaceRegistrants.RaceYear
    ORDER BY VRCRaceRegistrants.PSNID, Sum(VRCRaceRegistrants.Points) DESC;

    It lists data as such:

    Year Driver Points
    2011 Driver1 100
    2012 Driver1 200
    2011 Driver2 150
    2012 Driver2 100
    2011 Driver3 100


    I want to show the difference between 2011 and 2012, like so:

    Driver Diff
    Driver1 +100
    Driver2 -50
    Driver3 Null


    I there another query I need to write or a tweek to this one?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Let's see if I correctly understand requirement. Last time I suggested subquery method I had misread the OP.

    Review http://allenbrowne.com/subquery-01.html, especially the example for 'Get the value in another record'

    Or try:

    SELECT Table1.Driver, Sum([Points]*IIf([Year]="2011",-1,1)) AS PTs
    FROM Table1
    GROUP BY Table1.Driver
    HAVING (((Max(Table1.Year))="2012"));
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

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