sql - Oracle ranking columns on multiple fields -


I have some problems with some column ranking in Oracle. I have two columns that need to be ranked - A group id and a date.

I have to group the table in two ways - 1. Rank rank by record (rank_1) in each group_id 2. GROUP_ID by their DATETIME, GROUP_ID (RANK_2)

Should look:

  GROUP_ID | DATE | RANK_1 | RANK_2 ---------- | ------------ | ----------- | ---------- 2 | 1/1/2012 | 1 | 1 2 | 1/2/2012 | 2 | 1 2 | 1/4/2012 | 3 | 1 3 | 1/1/2012 | 1 | 2 1 1/3/2012 | 1 | 3   

I am able to pre-do, but I am unable to locate the latter.

  SELECT group_id, datetime, ROW_NUMBER () over (date_date by group_id from time to time) AS RN, DENSE_RANK () ORDER (by group_id) AS rn2 table_1 ORDER by group_id;   

This incorrectly commands the RANK_2 area:

  GROUP_ID | DATE | RANK_1 | RANK_2 ---------- | ------------ | ----------- | ---------- 1 | 1/3/2012 | 1 | 1 2 | 1/1/2012 | 1 | 2 2 | 1/2/2012 | 2 | 2 2 | 1/4/2012 | 3 | 2 3 | 1/1/2012 | 1 | 3    

Assume that your table does not have the actual ID column, it seems that You want to rank second in every group as soon as possible. For this, nested subquery will be required: Choose from

  as RT2 (checklist group_id, datetime, ROW_NUMBER) more than (split), group_id, date time, rn, dense_rank (), ( ORDER BY group_id; as per initial date from the table_1) RN, minimum (day-time) over (split by group_id) table_1, according to group_ID order date by overlist date, order by group_id)    

Comments