Jump to content

select top 5 clients with most calls logged


shocker-z

Recommended Posts

Hi,

 

I'm at a dead brainer again!

 

What i need to do is select the top 5 client who have the most reccords in my database

 

so im guessing im going to have to group them to return how many clients are selected.

 

i was thinking somthing like

 

SELECT client FROM pronet

WHERE logged BETWEEN '$monthstart' AND '$monthend'

GROUP BY client

LIMIT 5

 

would work but it's not returning the top 5 highest.. also i could do with retuirning the number of calls in the database too.

 

 

Regards

Liam

SELECT COUNT(client) as ClientCount, client FROM pronet
                     WHERE logged BETWEEN '$monthstart' AND '$monthend'
                     GROUP BY client
                     ORDER BY ClientCount
                     LIMIT 5

 

Untested and not sure if it will work, but give it a shot.

$gettoploggedclients=mysql_query("SELECT client, count(*) as `clientcount` FROM pronet

WHERE logged BETWEEN '$monthstart' AND '$monthend'

GROUP BY client

ORDER BY clientcount DESC

LIMIT 5") or die('Error getting top logged clients: '.mysql_error());

 

that works just figured it myself :)

 

thanks anyway mate :)

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.