Jump to content

Recommended Posts

Im really not sure how to describe this so please bare with me on this.

 

I have a column in the database that stores our employee ID's whenever a new incident is submitted to the database.

 

What I was asked is to have a display of the top 5 ID's that call in the most.

 

So what I need is a query that will calculate the amount of ID's are in the database, count how many times each one called in and display the top 5 highest amount of ID's.

 

.... hope I explained that right.

 

Don't even know where to start with this.

Link to comment
https://forums.phpfreaks.com/topic/136749-solved-help-with-a-calculation-query/
Share on other sites

Hitting the gigerweb modified the query a bit but oddly getting the same result when I echo it

 

SELECT COUNT(flagentTID) FROM data GROUP BY flagentTID DESC LIMIT 5

 

Gives me

Resource id #130 
Resource id #130 
Resource id #130 
Resource id #130 
Resource id #130 

$sql = "SELECT flagentTID, COUNT(*) as total
          FROM data 
          GROUP BY flagentTID 
          ORDER BY total DESC 
          LIMIT 5";
$res = mysql_query($sql);
while (list($id, $tot) = mysql_fetch_row($res))
{
    echo "$id : $tot <br />";
}

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.