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!

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.

Aggregate Value at higher level

SQLE KumarMay 31 2025

Hi ,

I have a issue which I am looking to find the best optimized solution

  1. 01 Family ID is dummy data pasted below may have multiple Member id and there are around 111 questions that are answered for each member id
  2. Now we need to aggregate value at FAMILY_ID
  3. Example if Q1 has Y in any of member ID Family will have Y
  4. Example 2 Q4 if have Direct for any of its Member ID its Family ID will have Direct

I thought of using LISTAGG to aggregate value then use case but has multiple issue

  1. Will have to write 111 case statement for 111 Questions and each case will have multiple WHEN hence does not sound a great solution to me
  2. LISTAGG in oracle will concatenate till 4000 characters only what i response of concatenated string increases 4000

Kindly help

CREATE TABLE AGG_FAM_LEVEL
(
Family_ID NUMBER(50),
Member_ID NUMBER(50),	
Q1 VARCHAR2(4000),
Q2 VARCHAR2(4000),
Q3 VARCHAR2(4000),
Q4 VARCHAR2(4000),
Q5 VARCHAR2(4000),
)
;

INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (1234,12,'Y','TP','C','No Access','A');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (1234,76,'N','SP','P','will login using VPN','');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (1234,87,'Y','QP','PR','Direct','B');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (1234,65,'N','DF','C','','C');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (45,65,'Y','TP','C','No Access','A');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (45,34,'N','TG','P','will login using VPN','');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (45,32,'Y','QP','PR','Remote','B');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (45,36,'N','DF','C','','C');
INSERT INTO AGG_FAM_LEVEL (Family_ID,Member_ID,Q1,Q2,Q3,Q4,Q5) VALUES (45,36,'N','need to concatenate the strings ','C','CITRIX','C');
This post has been answered by Stew Ashton on Jun 1 2025
Jump to Answer
Comments
Post Details
Added on May 31 2025
7 comments
261 views