Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Failed in Order

Chloe_19Jan 5 2015 — edited Jan 6 2015

Hi

I am trying to Select ID with a N grade for STY05 in 1201 or 1202 Period (Either one (or can happen in both)) who are also present (went on to study) unit STY06 or STY07 for the same period or the next period (STY06/07 SAME OR NEXT PERIOD CANT BE IN A PERIOD BEFORE STY05)

I am trying to achieve the table at the very bottom.

ID 688 took STY05 in in 1201 and received an N grade for it then took STY06 in the SAME Period which makes the ID eligible. However did not take STY07 so I just have a null at the table below.

ID 551 took STY05 in in 1202 and received an N grade for it then took STY06 in the SAME Period which makes the ID eligible and also took STY07 the next period and got a grade (see table below)

Main thing is ID should NOT have take STY06/07 in a period BEFORE STY05

CREATE TABLE DAN_GGG

(ID     VARCHAR2(12),

PERIOD    number(5),

STATUS  VARCHAR2(12),

GRADE          VARCHAR2(12),

UNIT  VARCHAR2(12));

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('688', '1201' ,'PRESENT', 'N' ,'STY05');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('688', '1202' ,'PRESENT', 'N' ,'STY05');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('688', '1202' ,'PRESENT', 'P' ,'UPO');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('688', '1201' ,'PRESENT', 'N' ,'STY06');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('732', '1201' ,'PRESENT', 'N' ,'STY05');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('732', '1202' ,'PRESENT', 'P' ,'STY06');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('551', '1202' ,'PRESENT', 'N' ,'STY05');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('551', '1202' ,'PRESENT', 'P' ,'STY06');

INSERT INTO  DAN_GGG (ID,PERIOD,STATUS,GRADE,UNIT) VALUES ('551', '1203' ,'PRESENT', 'P' ,'STY07');

Want:

         

IDUnitSPGradeUnitSPGradeUnitSPGrade
688STY051201NSTY061201NSTY07NULLNULL
551STY051202NSTY061202PSTY071203P
This post has been answered by Etbin on Jan 6 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 3 2015
Added on Jan 5 2015
6 comments
1,305 views