|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Complicated Query?
I am a newb. Using MySQL. I am trying to get some statistical information from a table called answers. Basically the kinds of things I want to know are similar to the problem below.
There are four important columns AID (the key or whatever) UID ( a user ID) QID (a question ID) and ANSWER (the answer to the specific question). What I have done is made a seperate table of questions with unique QIDs and a seperate table (outlined above) for answers. The problem is I have multiple rows for each user, each row relating to a different QID, and having a different answer in the ANSWER column. What I want to do is find out how many people answered QID=1 as ANSWER="5" and also answered QID=2 as ANSWER="10". I don't know if this will layout properly: AID UID QID ANSWER 1 1 1 5 2 1 2 10 3 1 3 99 4 2 1 3 5 2 2 9 6 2 3 60 7 3 1 5 8 3 2 17 9 3 3 24 10 4 1 5 11 4 2 10 12 4 3 93 So the answer to the query would be 2 (users 1 and 4) The question is how do i do this? A better question might be is this a completely inefficient way to be doing this? If there is I have open ears, but I would also like to know how to do it this way too Thanks, Kelly |
|
#2
|
|||
|
|||
|
RE: Complicated Query?
This is how:
SELECT count(uid) as number FROM table_name WHERE (QID=1 and ANSWER=5) or (QID=2 and ANSWER=10) And it's not inefficient. I'm sure there are other ways of storing this data, but this is a good one. You have a table with users, one with questions and one with answers, and here you just link them all. It's OK. |
|
#3
|
|||
|
|||
|
RE: Complicated Query?
Awesome, works great, THANKS A LOT!
Kelly |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Complicated Query? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|