Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old November 25th, 2003, 04:54 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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 Any help would be greately appreciated! I am in over my head and I have just begun.

Thanks,

Kelly

Reply With Quote
  #2  
Old November 25th, 2003, 05:59 AM
Seadoo Seadoo is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 133 Seadoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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.

Reply With Quote
  #3  
Old November 26th, 2003, 04:54 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Complicated Query?

Awesome, works great, THANKS A LOT!

Kelly

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Complicated Query?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway