Calculating score based on rank position
<p>I have a table <code>jackpot</code> with columns <code>uid</code> for user ID and <code>nright</code> for number of right answers. </p>

<p>I manage to SELECT and rank users by right answers, but what next?</p>

<pre><code>SELECT
    a1.uid,
    a1.nright,
    COUNT(a2.nright) AS rank
FROM
    jackpot a1,
    jackpot a2
WHERE
    a1.nright &lt; a2.nright
OR (
    a1.nright = a2.nright
    AND a1.uid = a2.uid
)
GROUP BY
    a1.uid,
    a1.nright
ORDER BY
    a1.nright DESC,
    a1.uid DESC
</code></pre>

<p>I need to calculate the amount of points to give to each user depending on his position. </p>

<p>Only users with top 3 MAX <code>nright</code> receive points.</p>

<p>The total amount of points = the number of users*20. </p>

<p>First position gets 70% of the total, 2nd - 20%, 3rd - 10%.</p>

<p>In case of equal right answers between users, the points are split evenly (50/50, 33/33/33...).</p>

<p><a href="http://sqlfiddle.com/#!9/50d5f/1" rel="nofollow noreferrer">SQL Fiddle</a></p>