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);
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.