Count Function Across Multiple Columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Der P
    New Member
    • Mar 2012
    • 2

    Count Function Across Multiple Columns

    I am trying to count the number of Pass and Fails across several different columns.
    For example, I have 10 columns that each result in a value Pass or Fail. I want a query that gives the count of all of each of those columns broken down by # of Pass and # of Fails.

    I used this code to count all of the Fails on 1 column:
    SELECT COUNT(CO_mtm) AS CO_mtm_FAIL FROM FXCompare
    WHERE CO_mtm='FAIL'

    This gives me all of the fails for column CO_mtm. However, how can I continue the SQL code to give me the # of fails for all the other columns i.e. CO_log, CO_otm, CO_date, etc. etc.

    THANKS.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Your data is poorly structured and should be normalized. As it is, it's going to make your queries more complex.

    Don't use a count, use a sum. And use the IIf function to assign a 1 for a pass and a 0 for a fail, if you're counting passes. Use the opposite for a fail count column.

    Comment

    • Der P
      New Member
      • Mar 2012
      • 2

      #3
      Thanks for reply. Unfortunately I'm a newbie with Access SQL and coding so appreciate your patience.
      Can you please explain in more detail (maybe code example?) how this would work.
      The problem I am having is doing and displaying this across multiple columns. I.e. I want to see the count of all the fails for ONLY the CO_mtm column, all the fails for ONLY the CO_log column, etc. etc.

      So my end result would be something like this:
      CO_mtm CO_mtm Count CO_log CO_log Count
      FAIL 54 FAIL 28
      PASS 7 PASS 53


      Thanks so much for your help.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Since you're new to SQL, the first thing you should do is find a good tutorial and learn SQL. Once you have that under your belt, you can implement my suggestion and post back here if you run into any errors.

        Comment

        Working...