| | |
finding a matches recursively
Please support our MS SQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2006
Posts: 3
Reputation:
Solved Threads: 0
I have a table to store the answers of users of our sweepstake. The table that consists of 3 fields: the userid, the questionid and the answervalue.
Now I need to find the users with the most identical answers as a certain user.
For example I may have values like this (excerpt and simplified):
userid,questionid,answervalue
15,1,1
15,3,5
15,4,1
15,14,0
495,1,1
495,2,1
495,12,0
498,1,1
498,2,5
498,3,5
498,4,0
Now, if I search the closest matches for user 15 I'should find out that user 495 has one match (question 1) and user 498 has two (questions 1 and 3)
I need the SQL to get this information and don't know how.
Any ideas? It shouldn't be that difficualt but after a little too less of sleep my brain is kind of resting.
Thanks a lot!
Now I need to find the users with the most identical answers as a certain user.
For example I may have values like this (excerpt and simplified):
userid,questionid,answervalue
15,1,1
15,3,5
15,4,1
15,14,0
495,1,1
495,2,1
495,12,0
498,1,1
498,2,5
498,3,5
498,4,0
Now, if I search the closest matches for user 15 I'should find out that user 495 has one match (question 1) and user 498 has two (questions 1 and 3)
I need the SQL to get this information and don't know how.
Any ideas? It shouldn't be that difficualt but after a little too less of sleep my brain is kind of resting.
Thanks a lot!
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
try this
MS SQL Syntax (Toggle Plain Text)
CREATE proc getMatches(@user int)AS SELECT count(a.userid) AS NumberOfMatches, a.userid FROM tblAnswers a, tblanswers b WHERE a.questionid = b.questionid AND a.answervalue = b.answervalue AND a.userid!= @user AND b.userid = @user GROUP BY a.userid
![]() |
Similar Threads
- Help finding modem driver for laptop (Windows NT / 2000 / XP)
- recursive findaverage function for Binary search tree (C)
- Finding an IP address using Java (was: do u know?) (Java)
- finding area of something (Computer Science)
- Finding Encrypted Files (Windows tips 'n' tweaks)
Other Threads in the MS SQL Forum
- Previous Thread: A simple question about hot key
- Next Thread: SQL problem - table names as variables
Views: 2209 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last autogrowth business connectingtodatabaseinuse count cursor data database dateadd datepart day" dbsize deadlock delete_trigger exploit getdate hack highperformancecomputing hpc hpcserver2008 ibm iis limit live loop maximum microsoft ms mssql multiple multithreading news number password permission position query reporting result security server services sets single source sql sql-injection sqlserver sqlserver2005 subtype supercomputing supertype tables uniqueid update view weekday





