Sorry if this is a basic question.
I have a table
store-ProdCode
13p I10x
13p I20x
13p I30x
14a K38z
17a K38y
my data set has nearly 100,000 records.
What I'm trying to do is, for every store find the top 10 prodCode.
I am unsure of how to do this but what I tried was:
select s_code as store, prod_code,count (prod_code)
from top10_secondary
where prod_code is not null
group by store,prod_code
order by count(prod_code) desc limit 10
this is giving me something completely different and i'm unsure on how I go about achieving my final result.
The expected output should be: for every store(s_code) display the top 10 prodcode (top 10 calculated by the count)
so:
store--prodcode--result
1a abc 5
1a abd 4
1a xxx 7
--- this will be done until top 10 prodcodes for 1a are done--
2a dgf 1
2a ldk 6
--process completes until end of data is reached and top 10 prodcodes are displayed for each store
All help is appreciated. What is the best way to do this?
Thanks