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 6565537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:06:22+00:00 2026-05-25T14:06:22+00:00

i have the following: CREATE TABLE R_TEST ( PROJECT_ID NUMBER, VERSION NUMBER, READY_DATE DATE,

  • 0

i have the following:

CREATE TABLE R_TEST
(
   PROJECT_ID  NUMBER,
   VERSION     NUMBER,
   READY_DATE  DATE,
   ESTATE_NO   VARCHAR2(1 BYTE)
  )
  TABLESPACE vvvvvvvvv
  PCTUSED    0
  PCTFREE    10
  INITRANS   1
  MAXTRANS   255
  STORAGE    (
        INITIAL          64K
        NEXT             1M
        MINEXTENTS       1
        MAXEXTENTS       UNLIMITED
        PCTINCREASE      0
        BUFFER_POOL      DEFAULT
       )
 LOGGING 
 NOCOMPRESS 
 NOCACHE
 NOPARALLEL
 MONITORING;
 SET DEFINE OFF;

 Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
 Values
    (1345, 1, NULL, 'a');
 Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
 Values
    (1345, 2, NULL, 'a');
 Insert into R_TEST
   (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
 Values
   (1345, 3, TO_DATE('07/01/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'a');
 Insert into R_TEST
   (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
 Values
   (1345, 4, TO_DATE('07/29/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'a');
 Insert into R_TEST
   (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
  Values
  (1059, 1, NULL, 'b');
 Insert into R_TEST
   (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
  Values
   (1059, 2, TO_DATE('06/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'b');
  Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
 Values
    (2326, 1, NULL, 'b');
 Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
  Values
    (2326, 2, NULL, 'b');
 Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
 Values
    (2326, 3, TO_DATE('08/29/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'b');
 Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
 Values
    (998, 1, NULL, 'c');
  Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
  Values
   (998, 2, TO_DATE('07/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'c');
  Insert into R_TEST
    (PROJECT_ID, VERSION, READY_DATE, ESTATE_NO)
  Values
   (998, 1, NULL, 'c');
  COMMIT;

I am trying to get how many active vs completed projects exist per estate_no. According to above data: I should have

one completed project on 7/27/2011 and one active project for estate_no C.
two completed projects on 8/29/2011 and 6/27/2011 for estate_no B.
one completed project on 7/29/2011 for estate_no A.

the problem i am having is that estate_no A has two dates for the same project_id with 4 different versions. They marked it ready but realized that it wasn’t actually ready, did some more work and then marked it ready one more time.

any help will be appreciated.

  • 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-25T14:06:23+00:00Added an answer on May 25, 2026 at 2:06 pm

    You should pick the row with the maximum version for an estate and a project.

    one way is to join a subquery containg the rows with maximum version:

    SELECT  r_test.project_id, r_test.version, r_test.ready_date, r_test.estate_no
    FROM r_test INNER JOIN (SELECT  project_id, estate_no, max(version) as max_version
                            FROM r_test
                            GROUP BY project_id,estate_no
                           ) sub_r_test 
    ON (r_test.project_id = sub_r_test.project_id
        and r_test.estate_no = sub_r_test.estate_no
        and r_test.version = sub_r_test.max_version
       )
    

    another way is to use oracle analytical functions to give row number on each line according to its group where the group is sorted in descending order of versions and then picking the lines that have the number 1 (they will be lines with max version)

    SELECT  project_id, version, ready_date, estate_no
    FROM (SELECT project_id,
           version,
           ready_date,
           estate_no,
           row_number() over (partition by project_id,estate_no order by version desc) rn 
          FROM r_test
         )  
    WHERE rn=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: CREATE TABLE TEST(ID TINYINT NULL, COL1 CHAR(1)) INSERT INTO
I have the following table: create table ARDebitDetail(ID_ARDebitDetail int identity, ID_Hearing int, ID_AdvancedRatePlan int)
I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables: CREATE TABLE title ( booktitle VARCHAR( 60 ), title_id
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have the following table in a SQLite3 database: CREATE TABLE overlap_results ( neighbors_of_annotation
I have a table defined by the following SQL: CREATE TABLE test ( id
I have the following table: CREATE TABLE [dbo].[Tree]( [AutoID] [int] IDENTITY(1,1) NOT NULL, [Category]

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.