SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2009
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Order by average of two columns MYSQL???

    Hi Guys,

    Wondering if anybody has any tips on ordering a select by the average of two columns in mysql

    For example..

    Price_min Price_max
    12000 14000

    In my DB I insert price_min and price_max, then on my php results page I want to sort and display my results by average price.

    Help very much appreciated.

    Thanks guys

    Stuart

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    695
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    order by (price_min + price_max)/2

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume you just want ((price_max + price_min) / 2). Just use that in you order by.


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
  •