Jump to content

max and count question??


Skipjackrick

Recommended Posts

I have a table where I am counting the number of a particular species in my database.  On my Display page I only want to show the highest value of species for that particular team.

 

Is it possible to use the MAX() script to display the highest "COUNT()" value only?

 

For example,

 

Team A = 4 Red Drum

Team B = 9 Red Drum

Team C = 1 Red Drum

 

My display table would only show Team B with 9 Red Drum

 

Below is my count query for the total counted species of a particular id.

$query_sum = "SELECT species_id, team_id,
	COUNT(species_id)
	FROM submit
	WHERE species_id=1
	GROUP BY team_id"; 

 

But, how would I display only team B.  Here is what I have so far and it displays all of the teams and the total number of that species.

 

while($row = mysql_fetch_array($result))
{
$team_id = $row['team_id'];
$redfish = $row['COUNT(species_id)'];

//get team's name from team table
get_team_name($team_id);

$_details .=<<<EOD
<tr>
	<td align='center'>$teamname</td>
	<td align='center'>$redfish</td>
</tr>
EOD;
}
$_footer ="</table>";

$species_total =<<<SPECIESTABLE
	$_details
	$_footer
SPECIESTABLE;

print $species_total;
?>

 

 

Link to comment
Share on other sites

I figured it out guys.  I just had to insert a LIMIT 1 statement.

 

Thanks anyways.

 

$query_sum = "SELECT species_id, team_id,
	COUNT(species_id)
	FROM submit
	WHERE species_id=1
	GROUP BY team_id
                ORDER BY COUNT(species_id)
                LIMIT 1"; 

 

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.