473,413 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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:

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.

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_quality"?

Matt

Jul 1 '07 #1
2 1740
>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_quality"?
select count(*) from survey where writing_quality=1;

If you want the whole distribution of votes:

select writing_quality, count(writing_quality) 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_quality)
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_quality) from survey;

which might give you 2.8 as an average.

You can also try things like:

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

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

Jul 1 '07 #2
On Jul 1, 7:47 pm, gordonb.fs...@burditt.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:
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_quality"?

select count(*) from survey where writing_quality=1;

If you want the whole distribution of votes:

select writing_quality, count(writing_quality) 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_quality)
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_quality) from survey;

which might give you 2.8 as an average.

You can also try things like:

select avg(writing_quality) 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

Jul 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sydemon | last post by:
Hello, I have the 3.2.2 version of the big nose bird survey script and have a problem with cookies. When i allow the survey users to view the results, the cookies work and prevent multiple votes....
5
by: spike29 | last post by:
Hello can any teach me how to make a survey like the one you see on ESPN. with color rows and and percentages on the side and the number of votes in XHTML :)
1
nitindel
by: nitindel | last post by:
Hi All, Greetings...!!! I want to have a survey form in an asp Page..and when the user submits in any of the radio buttons..i want to show the results in percentage.. i have used the...
3
by: nitric | last post by:
hey guys, i'm really stuck on this program. It's basically a survey and I have to ask people what drinks they like. 1-4, coffee tea oj and lemonade. i'm having trouble counting the TOTAL NUMBER...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.