Results 1 to 7 of 7
  1. #1
    SpookiePower is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Denmark
    Posts
    14

    A - B = C, show all 3 columns ?


    I have this SQL -

    SELECT (SUM(A) - SUM(B)) AS C
    From table1

    which shows the result, as it should do, but only shows C. What I would like to do, it to show all 3 results, like 1000 900 100

    I have tried this -

    SELECT ((SUM(A) AS A) - (SUM(B) AS B)) AS C

    But it will not work as I want it to.

    Anyone have an idea to the solution?

    - Kim -

  2. #2
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    A - B = C, show all 3 columns ?

    You need them as separate fields
    Code:
    SELECT SUM(A) AS A, SUM(B) AS B, (SUM(A) - SUM(B)) AS C FROM table1
    Original
    Code:
    SELECT (SUM(A) - SUM(B)) AS C FROM table1

  3. #3
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Alex is correct, except you can't use "AS A" and "AS B" again. The "A" and "B" are already define in Table.

    Something like this will work.
    SELECT Sum([A]) AS ASum, Sum([B]) AS BSum, (Sum([A])-Sum([B])) AS C
    FROM table1;

  4. #4
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    A - B = C, show all 3 columns ?

    Good catch, wasn't thinking!

  5. #5
    SpookiePower is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Denmark
    Posts
    14
    Thanks to both of you I'll try it when I get home later to day

  6. #6
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Slightly more efficient to give it a different name anyway.

    Code:
    SELECT 
       MyGroup,
       Sum(A) As SumA, 
       Sum(B) as SumB, 
       SumA-SumB As SumC
    FROM 
       MyTable
    GROUP BY 
       MyGroup;

  7. #7
    SpookiePower is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Denmark
    Posts
    14
    Thanks It works

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

Similar Threads

  1. show / hide columns based on criteria?
    By stevepcne in forum Access
    Replies: 1
    Last Post: 11-18-2011, 02:49 PM
  2. Replies: 6
    Last Post: 02-24-2011, 03:24 PM
  3. Replies: 1
    Last Post: 01-24-2011, 03:03 PM
  4. Show/Hide Columns in a Query
    By SCFM in forum Access
    Replies: 1
    Last Post: 02-23-2010, 08:04 AM
  5. Show/Unshow Columns in Query
    By simmurray in forum Queries
    Replies: 0
    Last Post: 03-28-2009, 10:03 AM

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