From: Peter Brawley Date: June 17 2007 2:49pm Subject: Re: Help with AVG query List-Archive: http://lists.mysql.com/mysql/207524 Message-Id: <46754A15.70404@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------080709080600060208030208" --------------080709080600060208030208 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Reynier, >Normally with PHP I add every field, I mean (eval1, eval2, >eval3, eval4, eval5) and then divide this result by 5, like >a average. I know that SQL can do this directly using AVG >function but I don't know how. Can any help me? AVG computes an average across rows. If I understand you correctly, you want the average of five columns within each row? That would be ... SELECT (eval1+eval2+eval3+eval4+eval5)/5 as mean FROM ... and if you want the average of that ... SELECT AVG( (eval1+eval2+eval3+eval4+eval5)/5 ) AS superavg FROM ... PB ----- Reynier Perez Mira wrote: > Hi every: > > I have this table: > > > > smp_evaluacion > > --------------- > > id_evaluacion > > eval1 > > eval2 > > eval3 > > eval4 > > eval5 > > > > This is for a rating system. I need to build a query for retrieve the best rating files. Normally with PHP I add every field, I mean (eval1, eval2, eval3, eval4, eval5) and then divide this result by 5, like a average. I know that SQL can do this directly using AVG function but I don't know how. Can any help me? > > > > Cheers and thanks in advance > > > > > > Reynier Pérez Mira > > 5to. año Ing. Informática > > Universidad de las Ciencias Informáticas > > > > > > ------------------------------------------------------------------------ > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.472 / Virus Database: 269.9.0/852 - Release Date: 6/17/2007 8:23 AM > --------------080709080600060208030208--