var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Help with select for toplist
Hello!! I have a toplist which picks out five top items per day from a list.
Columns are ID (serial), ITEM (varchar), weekday (INT), and SCORE (INT)
The select for top five competitors for day X :
Also I have this page where all results for a week is presented, and rather than doing seven selects (for X in (0..6)) how can I make a select for top five of each day)
is SELECT id, item, score FROM mytable WHERE weekday=X ORDER BY score DESC LIMIT 5
Which version of pg are you using? If its 8.4 or newer you can use analytic functions.
SELECT * FROM (
SELECT id, item, weekday, score,
RANK() OVER (PARTITION BY weekday ORDER BY score DESC) rnk
WHERE rnk <= 5