Forum Moderators: coopster

Message Too Old, No Replies

Biggest 3 avgs of 3 cols from mysql table

         

smagdy

2:53 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



hi all,

I want to make a mysql query that get biggest 3 numbers from a table but not from 1 col but from avg of 3 cols.

Ex.
col1  col2  col3
10 10 10
20 20 20
30 30 30
40 40 40
50 50 50

the query should output biggest 3 avgs:
150
120
90

thanks in advance

arran

3:04 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



If your table has the form

table_1 (col_id, col_1, col_2, col_3)

then:

select col_id, (col_1 + col_2 + col_3)/3 as 'col_av' from table_1 order by col_av desc limit 3

should work.

smagdy

3:30 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Thanks a lot i will eat then give it a try :)

I thought of it like that but ive bad experience using computations inside the mysql query itself..

thanks