Results 1 to 4 of 4
  1. #1
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170

    3 Fields, 1 Total

    Hi Folks,

    Got a new question for today:



    I have a table with 4 fields:

    Date
    Operator1
    Operator2
    Operator3

    How do I create a query that counts all the recods where "Johnny" shows up in Operator1, Operator2, or Operator3?

    Thanks,

    Tony

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    A perfect example of how unnormalized data can make simple tasks harder than they have to be!

    A well-designed table should be structured like this, with only three fields.

    Date
    Operator Number
    Operator Name

    So then, the task is pretty easy, as you can create a Totals Query and Group By the Operator Name field and use the Count function on one of the other fields to get your account.

    As you currently have it structured, there are a few different ways to do it. Here are a few:

    Count each of the three Operator columns separately (via queries), and then add them
    - or -
    Create a query with a calculated field that will return a 1 if any of the three fields have that name in there, and a 0 otherwise.
    Then you can Perform a Totals Query and use the SUM function on this calculated field to get your count.

  3. #3
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Code:
    SELECT Count(MyTable.MyDate)
    FROM MyTable
    WHERE ((Operator1 = "Johnny")  
       OR  (Operator2 = "Johnny")  
       OR  (Operator3 = "Johnny"));
    or, if you want to count anything that starts with John, use
    Code:
    SELECT Count(MyTable.MyDate)
    FROM MyTable
    WHERE ((Operator1 Like "John*")  
       OR  (Operator2 Like "John*")  
       OR  (Operator3 Like "John*")) ;

  4. #4
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    You're the man Dal. Thanks!

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

Similar Threads

  1. Sub Total From 3 fields
    By bharatdubole in forum Access
    Replies: 3
    Last Post: 11-29-2012, 01:42 AM
  2. Total between 2 fields
    By jenncivello in forum Queries
    Replies: 3
    Last Post: 11-23-2012, 03:05 PM
  3. Replies: 3
    Last Post: 06-01-2012, 03:24 AM
  4. Divide two Fields, Total in another field
    By prawln in forum Access
    Replies: 1
    Last Post: 03-28-2011, 06:45 PM
  5. total many fields by function
    By thetuyen in forum Access
    Replies: 2
    Last Post: 03-08-2010, 08:43 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