Jump to content

Find the largest value for each group and sum and then sum those results!?!?!


Skipjackrick

Recommended Posts

I know we were just discussing this on this other topic...

http://www.phpfreaks.com/forums/mysql-help/find-the-largest-value-for-each-group-and-sum/

 

And it worked beautifully....

 

But now I want to group those results by the team that each angler is on.... Or SUM those results and group them by team... Is that possible?

 

For example, the following code outputs.......

 

totalinches.PNG

 

<?php
//connect to the db
include 'db_connect.php';

      //Testing for total inches
      $total_inches = "SELECT
                angler, team_id, SUM(mlength)
                FROM (
                         SELECT angler, yyyy, team_id, MAX(length) AS mlength
                            FROM submit WHERE yyyy=2010 GROUP BY angler, species_id
                     ) AS zz
      GROUP BY angler
      ORDER BY SUM(mlength) DESC
                ";
      $total_inches_result = mysql_query($total_inches) or die(mysql_error());

      $RowCount = mysql_num_rows($total_inches_result);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.