Results 1 to 2 of 2
  1. #1
    bigmike is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2013
    Location
    New Mexico
    Posts
    3

    subtracting sum of tbl.unit1 from sum of tbl.unit2 in SELECT statement

    I have a database with two tables, Revenue and Expenditure. Each have a budget field. I would like to write a query that will show the sum of each of these two fields and the surplus left after expenditures are subtracted from revenues.

    I have tried:

    SELECT sum(Revenue.[budget]), sum(Expenditure.[budget]), sum(Revenue.[budget] - sum(Expenditure.[budget])
    FROM Revenue, Expenditure;

    The above query returns
    $13,014,539,791.00, $14,945,685,000.00 and ($1,931,145,209.00)
    The only one of these three number that s partially correct is the Expenditures, the middle number, but it's 10x what it should be.
    The other two numbers make now sense at all.

    Selecting one at a time seems to work unless subtraction is used:
    the query SELECT sum(Revenue.[budget]) FROM Revenue;
    returns
    $16,207,397.00 this is the correct sum
    SELECT SUM(Expenditure.[budget]) FROM Expenditure;
    returns
    $14,945,685.00 this is also the correct sum
    and SELECT (SUM(Revenue.[budget] - SUM(Expenditure.[budget])) FROM Revenue, Expenditure;
    returns


    ($1,931,145,209.00) a negative number and not correct even if it was positive

    how do I return multiple sums and the difference between the two ?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You need a join between the tables on whatever field(s) relate them. If there is none, you need to do them separately.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. when (select statement within inner join should be used)?
    By learning_graccess in forum Programming
    Replies: 1
    Last Post: 05-17-2012, 01:54 PM
  2. Running a Select statement in VBA
    By geraldk in forum Forms
    Replies: 12
    Last Post: 05-04-2012, 01:23 PM
  3. Need a select statement
    By gahawy in forum Queries
    Replies: 5
    Last Post: 01-15-2011, 04:02 PM
  4. select statement
    By jellybeannn in forum Access
    Replies: 5
    Last Post: 08-13-2010, 05:21 AM
  5. What is wrong with my SQL Select statement?
    By John2810 in forum Programming
    Replies: 2
    Last Post: 04-01-2010, 10:30 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