Jump to content

Need help for generating sql for parametric search


mabus

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.