I have a table with statistic data (roughly 100,000 rows) that has the following format:
WeekNum Name Value Category
201751 Joe 15 X
201751 Max 23 X
201751 Jim 7 X
201752 Joe 18 X
201752 John 17 X
201752 Max 31 X
201752 Jim 13 X
etc.
Now I would like to create a line chart with Google Charts to show the Top 10 over time. I want to create a JSON that then feeds the Google Chart API. The chart should look something like this:
How do I do the query to get the top 10 for each week? I came across some Rank questions here and adapted my query like this:
SELECT S.WeekNum, S.Name, S.Value, @curRank := @curRank + 1 AS Rank
FROM table S, (SELECT @curRank := 0) R
WHERE S.Category = 'X'
ORDER BY S.WeekNum, S.Value DESC
But this ranks all the records and I get back hundreds of records. Is it possible to get only the Top 10 for each week, and then do the ranking?
Thanks in advance for your help.