Results 1 to 2 of 2
  1. #1
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107

    Multiple Select Statements with Calculations

    I'm really going crazy here. I need to be able to update some data. Apparently this isn't possible with ways that I had posted before, so I'm going in a new way. How can I select multiple data so I don't need to have 3 different query tables? I've never understood the whole multiple selection thing.



    ProductNo Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Type
    12345667 .1 .3 .4 0 0 1 .2 14 .4 22 .22 7 FT
    89070172 0 0 0 0 0 2 .5 1 .5 1 22 .3 PT
    12345667 .3 66 7 0 0 0 12 .1 .2 0 0 0 PT
    89070172 11 1 1 1 1 1 1 1 0 0 0 0 FT
    68903421 0 0 0 0 0 0 0 0 1 1 1 1 FT

    What I need is the average number of workers per quarter, grouped by project and Type. The way I've been doing it has been to create quarter averages by selecting them:

    1.
    Code:
    SELECT Qtr1: (nz([Nov],0)+nz([Dec],0)+nz([Jan],0))/3, nz([Feb],0)+nz([Mar],0)+nz([Apr],0))/3 AS Qtr2, (nz([May],0)+nz([Jun],0)+nz([Jul],0))/3 AS Qtr3, (nz([Aug],0)+nz([Sep],0)+nz([Oct],0))/3 AS Qtr4
    Which is saved as a query table called "Resources".

    2. Then pulling the different types together and grouping by project:
    Code:
    SELECT Resources.ProductNo, Sum(Resources.Qtr1) AS AvgQtr1, Sum(Resources.Qtr2) AS AvgQtr2, Sum(Resources.Qtr3) AS AvgQtr3, Sum(Resources.Qtr4) AS AvgQtr4
    FROM Resources
    WHERE (((Resources.Type)="PT"))
    GROUP BY Resources.ProductNo;
    And saving this as a query table called "PT Resources".

    Is there a way to do the above 2 steps in one single select query? Please help, I feel I may punch my monitor any second now!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    You can nest the queries. Would have to go to the SQL View editor and edit the second query. Copy/Paste the first query SQL into the second. Look like:

    FROM (SELECT ...) As Resources
    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.

Similar Threads

  1. Calculations with a multiple value field
    By ashwin09 in forum Forms
    Replies: 12
    Last Post: 07-31-2011, 11:22 AM
  2. Multiple SQL Statements
    By springboardjg in forum Queries
    Replies: 1
    Last Post: 04-18-2011, 10:32 AM
  3. Multiple IIF statements
    By KevinMCB in forum Queries
    Replies: 4
    Last Post: 12-03-2010, 01:35 PM
  4. Nested Select Statements in FROM clause
    By neonslip in forum Queries
    Replies: 11
    Last Post: 11-03-2010, 10:58 AM
  5. Replies: 3
    Last Post: 10-13-2010, 03:35 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