--#请在BEGIN - END之间添加实现代码, 其余代码不能改动
create TYPE ret as(rank bigint, SCORE float);
create or replace
function select_topN(topN INT)
RETURNS SETOF ret
AS $$
BEGIN
RETURN QUERY
WITH ranked_scores AS(
SELECT score, DENSE_RANK() OVER(ORDER BY score DESC) as rank FROM score
)
SELECT rank, score
FROM ranked_scores
WHERE rank <= topN
ORDER BY rank, score DESC;
END;
$$
language PLpgsql;