I am using mysql to fetch this result from the database.I need to caluclate the rank of a prticular user id from this result.What is the easy and smart way of doing it?
SELECT a.UserId,d.AreaId,d.SubjectId, SUM( a.Marks ) AS sum, COUNT( a.Marks ) AS count, SUM( a.Marks ) / COUNT( a.Marks ) AS avg, b.PublicGroupId
FROM progressreport a, publicgroupmap b, qpaper c, subjects d,areas e
WHERE b.PublicGroupId = '10'
AND a.UserId = b.UserId
AND c.QpaperId = a.QpaperId
AND c.SubjectId = d.SubjectId
AND d.AreaId='2'
GROUP BY d.AreaId,a.UserId
ORDER BY avg DESC
`