getting top count across multiple fields
am 11.06.2006 02:48:44 von midnight_use_onlyalthough i don't think this is do-able using SQL, i would ask and maybe
an expert can help me out. assum i have the following table:
Date Code Count
2006-06-06 abc 1234
2006-06-06 abc 14
2006-06-06 abc 87
2006-06-06 xyz 1353
2006-06-06 xyz 19
2006-06-06 xyz 86
2006-06-06 xyz 176
2006-06-06 xyz 43
2006-06-06 ppp 67
2006-06-06 ppp 45
2006-06-06 ppp 200
what i want is the top 2 Count from each Code for Date like this:
Date Code Count
2006-06-06 abc 1234
2006-06-06 abc 87
2006-06-06 xyz 1353
2006-06-06 xyz 176
2006-06-06 ppp 200
2006-06-06 ppp 67
obviously the following doesn't work:
select Date,Code,Count from myTable group by Date,Code,Count order by
Count desc limit 2
because the order and the limit will be across the whole table not code
by code so you end up with only 2 rows with count 1353 and 1234.
any idea if this is do-able using SQL only?