SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    Barcelona
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to use an aggregate function ACROSS columns?

    I have a dataset that has 6 columns of values, and I want the maximum for each row ACROSS the columns. It seems that MAX(), SUM() etc work within the columns, but not across them.

    Does anyone know of a way to MAX across columns, or a cunning SQL statement that would do the job using a temptable?

    BTW, I cannot modify the database structure, so normalising the dataset is out the window.
    Juddster

  2. #2
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
     select (columna + columnb + columnc) as rowtotal from mytable

  3. #3
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    695
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    select greatest(c1,c2,c3,c4,c5,c6) from t
    requires 4.1

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    Barcelona
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet, thx guys!
    Juddster


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
  •