Results 1 to 2 of 2
  1. #1
    jbr87 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    14

    Conditional count in query

    Hi guys and girls,



    I posted this in the general forum but realized that this is the more apropriate forum for this discussion.

    I'm looking to build a querry that finds duplicate entries of a feild named "assembly_position" and contains two counts, one count that finds the number of times an entry is duplicated. The second count has to count how many of the duplicate entries have been shipped by looking into a "load" feild checking if the field is not null.

    so we take my table1:

    Code:
    AsemPos, load
    A1, l1
    A1, l2
    A1, 
    A3, l1
    A2,
    A2,
    A3,
    the result I'm looking for is:

    Code:
    AsemPos, Countod unique AP, Count of shipped
    A1, 3, 2
    A2, 2, 0
    A3 ,2 ,1
    I currently am able to get the unique entries as well as the first count with the following SQL statments

    SELECT Sheet1.Assembly_position, Count(Sheet1.Assembly_position) AS CountOfAssembly_position
    FROM Sheet1
    GROUP BY Sheet1.Assembly_position;

    What I need help with is the conditional count of the Items that have been shipped.

    Thanks,
    Jeff

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    You need 3 queries for this. First to pull the overal count, then to pull the count where load is not null, then to combine them. We'll call the first query qryTotalCount and the second qryLoadCount.

    Code:
    SELECT Sheet1.Assembly_position, Count(Sheet1.Assembly_position) AS CountOfAssembly_position
    FROM Sheet1
    GROUP BY Sheet1.Assembly_position;
    Code:
    SELECT Sheet1.Assembly_position, Count(Sheet1.Assembly_position) AS CountOfShipped
     FROM Sheet1
    WHERE Sheet1.Load Is Not Null
     GROUP BY Sheet1.Assembly_position;
    Code:
    SELECT qryTotalCount.AsemPos, qryTotalCount.CountOfAssembly_position, qryLoadCount.CountOfShipped
    FROM qryTotalCount LEFT JOIN qryLoadCount ON qryTotalCount.Assembly_position = qryLoadCount.Assembly_position;

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

Similar Threads

  1. Conditional count
    By jbr87 in forum Access
    Replies: 2
    Last Post: 09-28-2011, 05:55 AM
  2. Conditional Query
    By thegladiator in forum Queries
    Replies: 1
    Last Post: 01-14-2011, 11:44 AM
  3. Conditional Query Question
    By Silver Rain 007 in forum Queries
    Replies: 0
    Last Post: 11-16-2009, 11:30 AM
  4. count with conditional
    By humpz in forum Reports
    Replies: 3
    Last Post: 08-02-2009, 08:11 AM
  5. Conditional Format Query
    By Schwagr in forum Queries
    Replies: 3
    Last Post: 03-20-2006, 02:39 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