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

  • SEARCH
  • Home
  • 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 8489017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:42:31+00:00 2026-06-10T21:42:31+00:00

I am using Oracle SQL Developer to attempt to automatically calculate periods of absence

  • 0

I am using Oracle SQL Developer to attempt to automatically calculate periods of absence from an HR table. This table has the following relevant fields:
Person_Ref – Unique person identifier
START_DATE – The date that a period of absence commenced.
COMPDATE – Seems to be a 6-digit number which counts downwards, so lowest number is most recent.
I ultimately wish to write a statement that will rank the absence start dates for every person, take the newest START_DATE (i.e. lowest COMPDATE), and the 3rd newest START_DATE, then mathematically calculate the number of days between them (n.b. this table contains decades of absence, each entry indexed against PERSON_REF). This is a business requirement to report on cases where there are more than 3 periods of absence in 12 months (i.e. have the start dates of the last 3 periods of absence all fallen within 12 months).

I intend to firstly extract PERSON_REF, newest START_DATE, 3rd newest START_DATE, and COMPDATE into a separate table, hopefully with one line per PERSON_REF, then do the rest of the logic in Visual Studio. However this is where my SQL knowledge lets me down.

I can easily get ranked dates returned if I run this statement for a specific PERSON_REF:

SELECT D57.PERSON_REF, D57.START_DATE, D57.COMPDATE, RANK() OVER (ORDER BY D57.COMPDATE asc) rnk
From D57
WHERE D57.PERSON_REF='050050713';

From there I can pick the 1st & 3rd dates from the results in the rest of my query.

However, if I removed the WHERE command, then obviously it just ranks the entire table in order.

What I really want to know is, how can I write this sub query to return ranked results per PERSON_REF for every PERSON_REF in the table?

  • 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-06-10T21:42:32+00:00Added an answer on June 10, 2026 at 9:42 pm

    Use the Partition by clause

    SELECT 
        D57.PERSON_REF, D57.START_DATE, D57.COMPDATE, 
        RANK() OVER (PARTITION BY PERSON_REF ORDER BY D57.COMPDATE asc) rnk 
    FROM D57 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Oracle SQL developer to create a basic table with the following
I am using Oracle SQL Developer and trying to export a table to a
Newbie SQL Query question: I'm using Oracle SQL Developer. I have a table: <name>
In Oracle SQL Developer, one can list the data in a table using the
I am using Oracle SQL Developer. I essentially have a table of pictures that
Using Oracle SQL Developer I'm trying to access a given package that has been
I'm trying to import some data (using oracle sql developer) from a .csv file
I'm using Oracle SQL Developer to query an Oracle DB (not sure which version
I am using Oracle SQL Developer, but I am having an issue seeing results
I'm using Oracle SQL Developer. I'd like to key in dates with hours and

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.