Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:22:41+00:00 2026-05-31T07:22:41+00:00

Say, I have following table. USER_POINT USER_ID | BIGINT | PK USER_POINT | BIGINT

  • 0

Say, I have following table.

USER_POINT
  USER_ID    | BIGINT | PK
  USER_POINT | BIGINT |

‘USER_POINT’ may be constantly updated.
With given USER_ID I want the number of distance from the top in the selection ordered by USER_POINT.

SEQ    USER_ID  USER_POINT
-----  -------  -----------
00001  232132   32423423432
00002  023944   32423423431
.....  ......   ...........
01007  000034   xxxxxxxxxxx // I want to know the 01007 with given 000034

I’m not programmed yet but here comes some psuedocode I’m going to try.

public int getRank(final Long userId) {
    final int pageSize = 500;
    int pageCount = 0;
    int firstResult = 0;
    for (int firstResult = 0; true; firstResult += pageSize) {
        final Query query = em.createQuery(
            "SELECT u.id FROM UserPoint u ORDER BY u.point");
        query.setFirstResult(firstResult);
        query.setMaxResults(pageSize);
        final List orders = query.getResultList();
        if (orders.isEmpty()) {
            break;
        }
        final int index = orders.indexOf(userId);
        if (index != -1) {
            return pageSize * pageCount + index;
        }
        pageCount++;
    }
    return -1;
}

I want to ask

Is this the right way?
Is this the only way?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:22:42+00:00Added an answer on May 31, 2026 at 7:22 am

    JPQL doesn’t support such queries. You should use SQL for such queries if you want to make them efficient.

    In Oracle, such a query would look like

    select r from (select user_id, user_point, rownum as r 
                   from user_point 
                   order by user_point desc) where user_id = 34
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a 'user_log' table with the following field: id user_id status_text timestamp
Lets say I have the following table User_ID Manager_ID --------------------- Linda Jacob Mark Linda
Let's say that I have the following code: SELECT * FROM table where company
Say I have the following table: create table ratings ( user_id int unsigned not
Lets say I have the following mapping: <hibernate-mapping package=mypackage> <class name=User table=user> <id name=id
Let's say I have the following table: CustomerID ParentID Name ========== ======== ==== 1
Let's say we have the following table: CREATE TABLE T ( ID INT, String1
The idea is that say you have the following table. ------------- | oID |
Let's say I have the following simple table variable: declare @databases table ( DatabaseID
Let's say I have the following database table: record_id | record_date | record_value -----------+-------------+--------------

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.