Hi all, Thanks a lot for all the helpful replies. I knew how to do it through php but was wondering if it can be directly done with a mysql query ... what i basically wanted to do is display the records in a page with next/previous links (thus the need to use "limit") and display the sum of one or more fields. So, a where clause instead of the limit clause will not do.
I like the suggestion by Mike to insert the results into a temp table and then use the sum() on that table. But will this cause performance degradation when say 100 or so users visit the page simultaneously? Since this will mean creating a 100 or so temp tables and deleting them ... if this will degrade performance then I guess I'll have to go with the php summation. --- In [email protected], Mike Brandonisio <[EMAIL PROTECTED]> wrote: > > Hi Pete, > > Sorry for repeated posting. You can do your SUM() via PHP too. > > $query = mysql_query(select score from exams limit 20,10); > > //put scores in array > while ( $row = mysql_fetch_arry($query) ){ > //put responses into array to sum > $exam_scores[] = $row['score']; > } > //sum array of scrores > $sum_score = array_sum($exam_scores); > > Sincerely, > Mike > -- > Mike Brandonisio * Web Hosting > Tech One Illustration * Internet Marketing > tel (630) 759-9283 * e-Commerce > [EMAIL PROTECTED] * http://www.jikometrix.net > > JIKOmetrix - Reliable web hosting > > > On Aug 2, 2006, at 8:19 AM, agneady wrote: > > > Let's say I have a query like this one: > > > > select score from exams limit 20,10 > > > > So, it returns the scores for records 20-29 from the exams table. Now, > > I want the sum of these returned scores. If I use: > > > > select sum(score) from exams > > > > it returns the sum of all scores. What I want is the sum of scores x > > to y only. Can this be done with a MySQL query? I know I can do it in > > PHP easily, but I want to do it through a query if possible. > > > > > > > > > > > > > > The php_mysql group is dedicated to learn more about the PHP/MySQL > > web database possibilities through group learning. > > Yahoo! Groups Links > > > > > > > > > > > > > > > > > > > The php_mysql group is dedicated to learn more about the PHP/MySQL web database possibilities through group learning. Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php_mysql/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
