Jump to content

Selecting a row for a given amount


watsmyname

Recommended Posts

Hello,

 

Suppose i have a table structure

 

mID          pointtoIncrease              amountFrom            amountTo

1                    0                                      0                            99

2                    1                                      100                          499

3                    3                                      500                          999

4                    5                                      1000                        1499

 

I have to select "pointoIncrease" for given amount. Like i have amount 550, then the point is 3 because 550 lies between amountFrom=500 and amountTo=999. Sounds simple but i m not being able to write a query for that, can anyone please help me.

 

Thanks

 

Link to comment
Share on other sites

SELECT pointtoIncrease FROM your_table WHERE amount BETWEEN amountFrom AND amountTo

 

Thanks for the reply, i think query is not working. The query is

SELECT pointtoIncrease FROM sa_mileagepoints WHERE '1000' BETWEEN amountFrom AND amountTo

 

So, it should result 5 only, but the query is returning 3 rows, 1,5 and 0

 

and if amount is 550, it returns two rows 3 and 0

 

Link to comment
Share on other sites

What is the data type of your amountFrom  and  amountTo columns?

 

It would need to be an INT for math comparisons to work. Also, by putting the '1000' inside of single-quotes in the query, that makes it a string and strings are compared character by character starting with the left-most character.

Link to comment
Share on other sites

What is the data type of your amountFrom  and  amountTo columns?

 

It would need to be an INT for math comparisons to work. Also, by putting the '1000' inside of single-quotes in the query, that makes it a string and strings are compared character by character starting with the left-most character.

Oh thanks, got it the single quotes was causing a problem, thanks a lot

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.