mabus Posted August 25, 2008 Share Posted August 25, 2008 I would like to perform a query on a table (or group of tables) based on multiple parameters. I do not need the results to match all these parameters; matching at least one of the parameters is enough. However, I want to rank the results in such a way that those that match more parameters rank higher than those that match less parameters. Also, I would like to define a "weight" to each of the parameter to help sort the results. For example, say I have a Person table and did a search for: Gender = Male and Eye Color = Blue. Assume I have 4 records: 1. Gender = Male, Eye Color = Blue 2. Gender = Female, Eye Color = Blue 3. Gender = Male, Eye Color = Green 4. Gender = Female, Eye Color = Green The result should give me records #1, #2, and #3. Then let's say that I wanted to give more weight to Gender than Eye Color. Thus, my expected result would be this: #1, #3, and #2. How would I accomplish this? Quote Link to comment Share on other sites More sharing options...
fenway Posted August 25, 2008 Share Posted August 25, 2008 For example, say I have a Person table and did a search for: Gender = Male and Eye Color = Blue. ..... The result should give me records #1, #2, and #3. Assuming you mean logical AND and not database AND. If you want to weight it, then just SUM() up successive IF() expressions that give different weights. Quote Link to comment Share on other sites More sharing options...
mabus Posted August 26, 2008 Author Share Posted August 26, 2008 Hey thanks. Can I see some samples of that query? Quote Link to comment Share on other sites More sharing options...
fenway Posted August 26, 2008 Share Posted August 26, 2008 Like this: IF( gender = 'male', 10, 0 ) + IF( eye_color = 'blue', 5, 0 ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.