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:
| ID | Unit | SP | Grade | Unit | SP | Grade | Unit | SP | Grade |
| 688 | STY05 | 1201 | N | STY06 | 1201 | N | STY07 | NULL | NULL |
| 551 | STY05 | 1202 | N | STY06 | 1202 | P | STY07 | 1203 | P |