Home > Blockchain >  Oracle - result based on one column
Oracle - result based on one column

Time:09-10

I have the following data:

ITEM LOC ENABLED
100  A1   Y
100  A2   Y
100  A3   N

I want the result as:

ITEM     STATUS 
100     INACTIVE

If the ENABLED is marked N for any of the locations, it should return Status as INACTIVE If all locations are marked as Y, it should return ACTIVE

CodePudding user response:

One way:

select item, case min(status) when 'Y' then 'ACTIVE' else 'INACTIVE' end
  from t
 group by item;
  • Related