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!

SQL count with comma delimit

KGJ DevNov 6 2024 — edited Nov 7 2024

Hello,

I am using oracle 19c.

Below the same data and sample expected result. Basically i need to check if the MFR_TYPE_ID count > then 1 then print "Multiple and have the MFR_NAME as comma delimited. If the MFR_TYPE_ID count = then 1 then print “Single and have the MFR_NAME as comma delimited. How to achieve this result? can this be implemented without group by? please show me a sample query to achieve this result.

WITH
    Data (MFR_TYPE_ID, MFR_NAME)
    AS
        (SELECT '100-1234', 'Apple' FROM DUAL
         UNION ALL
         SELECT '100-1234', 'Nokia' FROM DUAL
         UNION ALL
         SELECT '100-1244', 'Samsung' FROM DUAL
         UNION ALL
         SELECT '100-1245', 'Facebook' FROM DUAL
         UNION ALL
         SELECT '100-1245', 'Microsoft' FROM DUAL
         UNION ALL
         SELECT '100-1245', 'DELL' FROM DUAL)
SELECT *
  FROM Data;


--- Expected Result 
WITH
    RESULT (MFR_TYPE, MFR_NAME)
    AS
        (SELECT 'Multiple', 'Apple,Nokia' FROM DUAL
         UNION ALL
         SELECT 'Single', 'Samsung' FROM DUAL
         UNION ALL
         SELECT 'Multiple', 'Facebook,Microsoft,DELL' FROM DUAL)
SELECT MFR_TYPE, MFR_NAME
  FROM Result;
This post has been answered by Lothar Armbrüster on Nov 7 2024
Jump to Answer
Comments
Post Details
Added on Nov 6 2024
8 comments
483 views