Oracle SQL - CASE When condition for ANY record
You can use conditional aggregation:
SELECT Doc_Name, CASE WHEN COUNT(CASE WHEN Doc_Owner <> Doc_Run_by THEN 1 END) > 0 THEN 'Y' ELSE 'N' END AS Share_StatusFROM Log_Table GROUP BY Doc_Name
If there is even a single record (within a Doc_Name
group of records) having Doc_Owner <> Doc_Run_by
, then Share_Status
will be equal to 'Y'
, otherwise it will be equal to 'N'
.