Group By Query - Count Multiple Choice Answers

Discussion in 'Database' started by jklose, Mar 12, 2010.

  1. jklose

    jklose New Member

    Mar 12, 2010
    Likes Received:
    Trophy Points:
    I'm trying to count answers to a series of multiple questions but can't get the SQL query to work properly.

    I have a table as follows:
    Q1 | Q2 | Q3
    Agree | Disagree | Strongly Agree
    Disagre | Agree | Agree
    Agree | Strongly Agree | Disagree
    I would like to output totals for each type of response for each question in a (query) table like:
    Answer | Q1Count | Q2Count | Q3Count
    Agree | 2 | 3 | 5
    Disagree | 1 | 5 | 3
    Strongly Agree | 4 | 3 | 2
    I've been trying a query like this:
    SELECT AnswersTable.Q1, Count(AnswersTable.Q1) AS Q1Count, Count(AnswersTable.Q2) AS Q2Count, Count(AnswersTable.Q3) AS Q3Count
    FROM AnswersTable
    GROUP BY AnswersTable.Q1
    ORDER BY AnswersTable.Q1 DESC;
    However, the output from this query is in the wrong order. While the counts for Q1 match the GROUP BY unique values, the other counts are disordered.

    Any tips on how to get the right output? Cheers.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice