Web Analytics Made Easy -
StatCounter Display sums in Descending order - CodingForum


No announcement yet.

Display sums in Descending order

  • Filter
  • Time
  • Show
Clear All
new posts

  • Display sums in Descending order

    Say i have a SQL query that gets the sum of several columns in the same table.

    mySQL = "SELECT Sum(tblUsers.ALP) AS SumOfALP, Sum(tblUsers.BLO) AS SumOfBLO, Sum(tblUsers.CHE) AS SumOfCHE, Sum(tblUsers.COL) AS SumOfCOL, Sum(tblUsers.CON) AS SumOfCON FROM tblUsers"

    Now the sums are in values like SumofBlo, SumofCoL, etc...

    Is there a way to now sort the sums values in order of highest value to lowest. Say sumofALP = 30, sumofChe = 50, sumofCOL = 20

    Can i sort it and display in DESCENDING order? I don't need to put the values of the fields in desc, asc or any kind of order before they're summed. I need the final sums of each colunm in descending order, if it's possible.

    So according to those example totals above, we'd have a display like so.

    SumofCHE (cause it = 50)
    SumofALP (cause it = 30)
    SumofCOL (cause it = 20)

    Any ideas?

  • #2
    order by col1 desc, col2 desc, col3 desc,.....colN desc and that should do the trick methinks..