Counting survey votes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    Counting survey votes

    Hi everyone,

    Constructed a fairly big table with 20 rows, most of which are
    TINYINTs based on user selection for a dropdown box. This is the form:



    Each field obviously corresponds to a row in the table, and the
    majority are integers indicating the user's selection.

    My issue is how to do meaningful stuff with the stored data. I believe
    I need to use GROUP BY functionality but I'm not certain - how can I
    calculate, say, the number of "1" ('Excellent') values for the field
    "writing_qualit y"?

    Matt

  • Gordon Burditt

    #2
    Re: Counting survey votes

    >Constructed a fairly big table with 20 rows, most of which are
    >TINYINTs based on user selection for a dropdown box. This is the form:
    >
    >http://www.threechords.org/spb/survey/
    >
    >Each field obviously corresponds to a row in the table, and the
    >majority are integers indicating the user's selection.
    This doesn't really have that much to do with PHP; it's more related to
    SQL and databases in general.
    >My issue is how to do meaningful stuff with the stored data. I believe
    >I need to use GROUP BY functionality but I'm not certain - how can I
    >calculate, say, the number of "1" ('Excellent') values for the field
    >"writing_quali ty"?
    select count(*) from survey where writing_quality =1;

    If you want the whole distribution of votes:

    select writing_quality , count(writing_q uality) from survey group by writing_quality ;

    which will get you a list of writing_quality values and the number
    of votes that gave that value, e.g.:

    writing_quality count(writing_q uality)
    1 32
    2 86
    3 74
    4 50
    5 22
    7 1

    (note: it seems nobody voted "6", so it is not listed).

    If you want an overall average:

    select avg(writing_qua lity) from survey;

    which might give you 2.8 as an average.

    You can also try things like:

    select avg(writing_qua lity) from survey where sex = 'Male' and age >= 20 and age < 30;

    which gives you a score from a specific segment of your users.

    Comment

    • Matt

      #3
      Re: Counting survey votes

      On Jul 1, 7:47 pm, gordonb.fs...@b urditt.org (Gordon Burditt) wrote:
      Constructed a fairly big table with 20 rows, most of which are
      TINYINTs based on user selection for a dropdown box. This is the form:
      >>
      Each field obviously corresponds to a row in the table, and the
      majority are integers indicating the user's selection.
      >
      This doesn't really have that much to do with PHP; it's more related to
      SQL and databases in general.
      >
      My issue is how to do meaningful stuff with the stored data. I believe
      I need to use GROUP BY functionality but I'm not certain - how can I
      calculate, say, the number of "1" ('Excellent') values for the field
      "writing_qualit y"?
      >
      select count(*) from survey where writing_quality =1;
      >
      If you want the whole distribution of votes:
      >
      select writing_quality , count(writing_q uality) from survey group by writing_quality ;
      >
      which will get you a list of writing_quality values and the number
      of votes that gave that value, e.g.:
      >
      writing_quality count(writing_q uality)
      1 32
      2 86
      3 74
      4 50
      5 22
      7 1
      >
      (note: it seems nobody voted "6", so it is not listed).
      >
      If you want an overall average:
      >
      select avg(writing_qua lity) from survey;
      >
      which might give you 2.8 as an average.
      >
      You can also try things like:
      >
      select avg(writing_qua lity) from survey where sex = 'Male' and age >= 20 and age < 30;
      >
      which gives you a score from a specific segment of your users.
      Thank you very much, I've managed to construct a nice-looking page
      (http://www.threechords.org/spb/survey/results.php) - apologies for my
      poor group choice here.

      Matt

      Comment

      Working...