SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Return results within certain percentage

    Hi guys

    I am pulling rows from my database

    PHP Code:
    SELECT Price
    FROM Products WHERE 

    What I need to do is pull all the products within 25% of the 'Price'

    So if Price is 1000 then 25% is 250

    So the database will return all results from 750 to 1250


    thanks in advance guys

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by wazo View Post
    Hi guys

    I am pulling rows from my database

    PHP Code:
    SELECT Price
    FROM Products WHERE 

    What I need to do is pull all the products within 25% of the 'Price'

    So if Price is 1000 then 25% is 250

    So the database will return all results from 750 to 1250


    thanks in advance guys
    Calculate lower and upper limit in PHP (if you use PHP), and then put
    Code:
    Price BETWEEN $lowerlimit AND $upperlimit
    in the WHERE statement of your query.

  3. #3
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT Price
      FROM Products
     WHERE Price BETWEEN (1000 * (1-0.25)) AND (1000 * (1+0.25))
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast


Bookmarks

Posting Permissions

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