Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    172

    Unanswered: find nearest value

    I have a table with values like this:

    amount fee
    $500 $35
    $700 $37
    $800 $42
    $950 $53
    $1,000 $60

    I want to look up (using a query) let's say, an amount of $850. The rule is: go to the next highest fee if the amount lies between 2 amounts.

    For example, $850 would return a fee of $53.

    What's a simple way to do this?

    Thanks in advance.

    Joe G

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    off the top of my head...

    select fee
    from feetable
    where amount =
    ( select min(amount)
    from feetable
    where amount > 850 )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2003
    Posts
    172
    I used greater than or equal to, just in case it was right on the lower number.

    That was what I needed. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •