www.webdeveloper.com
Results 1 to 3 of 3

Thread: median of integers using mysql

  1. #1
    Join Date
    Feb 2006
    Location
    india
    Posts
    678

    median of integers using mysql

    Hi Guys,

    How can I get the median of series of integers using mysql query.

    The integers are in database.

    Please suggest.

    Thanks,

  2. #2
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    Hi,
    here is a link to mysql Functions:

    http://dev.mysql.com/doc/refman/5.0/...functions.html

    There is a User comment suggesting tying the following:

    Code:
    For medians in almost any SQL:
    SELECT x.val from data x, data y
    GROUP BY x.val
    HAVING SUM(SIGN(1-SIGN(y.val-x.val))) = (COUNT(*)
    
    +1)/2
    assumes (COUNT(*)+1)/2 returns an int, if not
    then use INT((COUNT(*)+1)/2)
    There are variations for the varied defs of 
    median too.
    regards


    Ribs
    ----------------------------------

  3. #3
    Join Date
    Feb 2006
    Location
    india
    Posts
    678
    Hi Rib,

    Many thanks for the link.I will surely go through it now.

    Thanks once again.

    Raj

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles