groups, limits and counts.

2003-06-29 Thread Mark Rowlands
I have a tabletheres a surprise

month protocol port  utime
06  tcp21   12
06  tcp21   13
05  udp   43   100232
05  udp   21   100245

what I would like to do  is select by month and by protocol but within 
protocol limit to the top 5 by count of port.

 In other words,I want  the 5 most common instances of port per instance of 
protocol per instance of month.

is  this actually possible with a single query  (mysql 4.0)?

I have tried vairious combinations of group by and order by but however I do 
it, limit n, seems to do just that...limit the results to n rows... 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: groups, limits and counts.

2003-06-29 Thread Paul DuBois
At 13:18 +0200 6/29/03, Mark Rowlands wrote:
I have a tabletheres a surprise

month protocol port  utime
06  tcp21   12
06  tcp21   13
05  udp   43   100232
05  udp   21   100245
what I would like to do  is select by month and by protocol but within
protocol limit to the top 5 by count of port.
 In other words,I want  the 5 most common instances of port per instance of
protocol per instance of month.
is  this actually possible with a single query  (mysql 4.0)?

I have tried vairious combinations of group by and order by but however I do
it, limit n, seems to do just that...limit the results to n rows...
LIMIT is applied after all the other stuff.  It won't do what you want.

--
Paul DuBois, Senior Technical Writer
Madison, Wisconsin, USA
MySQL AB, www.mysql.com
Are you MySQL certified?  http://www.mysql.com/certification/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]