| | |
help with (hopefully) simple nested query
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 7
Reputation:
Solved Threads: 0
I'm writing a query to summarize survey results. There are two tables...
1) The Profiles table contains the users' answers. There are four columns: ProfileID (for the unique key), QuestionID (a number representing canned questions from another table), Answer (a number representing multiple choice answers from another table), and UserID.
2. The Users table has three columns that apply to the query: UserID (the same as that in the Profiles table) and Gender.
What I want to do is present a tally of how many people answered a question in a particular way. For instance, if I wanted to list people's favorite ice cream flavors, I'd want to see:
Now what I want to is group the results by Gender...
Thanks in advance.
1) The Profiles table contains the users' answers. There are four columns: ProfileID (for the unique key), QuestionID (a number representing canned questions from another table), Answer (a number representing multiple choice answers from another table), and UserID.
2. The Users table has three columns that apply to the query: UserID (the same as that in the Profiles table) and Gender.
What I want to do is present a tally of how many people answered a question in a particular way. For instance, if I wanted to list people's favorite ice cream flavors, I'd want to see:
CHOCOLATE 7With QuestionID 4 corresponding to the Ice Cream Flavor question, that was pretty straight-forward with...
VANILLA 4
ETC.
MySQL Syntax (Toggle Plain Text)
SELECT Profiles.Answer, COUNT(Profiles.Answer) FROM Profiles, Users WHERE Profiles.QuestionID =4 AND Users.UserID = Profiles.UserID GROUP BY Profiles.Answer;
Now what I want to is group the results by Gender...
CHOCOLATEHow do I write the nested query to group the first query's results by Gender?MALE 4VANILLA
FEMALE 3MALE 2
FEMALE 2
Thanks in advance.
Try that
Regards.
SELECT Profiles.answer, users.gender, COUNT(Profiles.answer) AS count
FROM Profiles INNER JOIN
users ON users.userid = Profiles.userid
GROUP BY users.gender, Profiles.answerRegards.
If your already resolved your issue, flag it as solved.
José Bisonó
José Bisonó
![]() |
Similar Threads
- OMG simple update query not working. PLEASE HELP! (MySQL)
- Query Time (ColdFusion)
- How to display a simple Access DB (ASP.NET)
- microsoft access simple date query (Computer Science)
- Range of records in Top clause (MS SQL)
- Php code confusion. Not sure how to describe (PHP)
- to write a query (Database Design)
- MySQL nested query / joined query conversion help (MySQL)
Other Threads in the MySQL Forum
- Previous Thread: Rows affected in mysql
- Next Thread: help wif uploading My sql database into Phpmyadmin.com
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm data database design developer development distinct drupal dui ec2 email enter eudora facebook form foss gartner gnu government greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





