'How to write a query to know the rank of a particular record?

Here's my query

 JPQLQuery<RankingListGetRes> query = jpaQueryFactory.select(new QRankingListGetRes(qStudyTime.user.nickname, qStudyTime.user.department.name, qStudyTime.time.sum()))
                .from(qStudyTime)
                .groupBy(qStudyTime.user).orderBy(qStudyTime.time.sum().desc());

this query calculates the rank of id in a column that is grouped by userid and sorted in descending order of time.

I want to extract the specific user's ranking(i know user id)

Is there a way to process it in 1 query? Or should I utilize more than 2 queries? I use mysql.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source