Skip to Main Content

Developer Community

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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Grouping and Flag the record

venkatesh867Feb 25 2024 — edited Feb 25 2024

Dear All,

Myself has the below 3 tables.

Request you to share the query to display the status for each department as either P or A or C.
P-Pending A-Accepted C-Completed

Prirority of status
C as top priority, A as second priority, P as least priority

The rules are as follows.

  1. If a department having more than one program and all the program having the equal status, then the flag column should return C
  2. If a department having more than one program and all the program does not having the equal status, then the flag should return A (second priority) or P(least priority)
  3. If a department having only one program then the flag column should give the priority for C as top priority, A as second priority, P as least priority and the flag column should return C (if the program has all the 3 status, if it has only P and A then it should return as A)

The table script and insert script are as follows

CREATE TABLE TABLE1 (Table1Id NUMBER, Deptid NUMBER);

INSERT INTO TABLE1 VALUES (1,101);

COMMIT;

CREATE TABLE TABLE2 (Table2Id NUMBER, Deptid NUMBER,ProgramID NUMBER);

INSERT INTO TABLE2 VALUES (1,101,1000);
INSERT INTO TABLE2 VALUES (1,101,1001);
INSERT INTO TABLE2 VALUES (1,101,1002);

COMMIT;

CREATE TABLE TABLE3 (Table3Id NUMBER,ProgramID NUMBER, Status VARCHAR2(10));

INSERT INTO TABLE3 VALUES (1,1000,'P');
INSERT INTO TABLE3 VALUES (1,1000,'A');
INSERT INTO TABLE3 VALUES (1,1000,'C');
INSERT INTO TABLE3 VALUES (1,1001,'P');
INSERT INTO TABLE3 VALUES (1,1001,'A');
INSERT INTO TABLE3 VALUES (1,1001,'C');
INSERT INTO TABLE3 VALUES (1,1002,'P');
INSERT INTO TABLE3 VALUES (1,1002,'A');

COMMIT;

Tables.png

Comments
Post Details
Added on Feb 25 2024
0 comments
86 views