Monday, 15 March 2010

mysql - sql select average from distinct column of table -



mysql - sql select average from distinct column of table -

in table have colms this, (beside cols)

col1 | col2 s1 | 5 s1 | 5 s2 | 3 s2 | 3 s2 | 3 s3 | 5 s3 | 5 s4 | 7

i want have average of all col2 on distinct col1. (5+3+5+7)/4=5

try this:

select avg(t.col2) (select distinct col1, col2 yourtable) t

mysql sql sqlcommand

No comments:

Post a Comment