Need SQL query help for the logic as below If at least 1 user under an account is "Enabled" then status = 'Active' If all users under an account are not "Enabled" then status = 'Cancelled' else 'Unknown'
create table usr (
acctid varchar(1),
usrid varchar(5),
sts varchar(20)
);
insert into usr values('A','U13','Enabled');
insert into usr values('A','U14','Enabled');
insert into usr values('A','U15','Disconnected');
insert into usr values('A','U16','Disconnected');
insert into usr values('B','U30','Disconnected');
insert into usr values('B','U31','Disconnected');
insert into usr values('C','U32',null);
insert into usr values('D','U133','Enabled');
insert into usr values('D','U12','Enabled');
Below is the expected result for status
CREATE TABLE...
) and DML (INSERT INTO...
) for the table above - you can do this in a fiddle. Also, please show us explicitly the result you desire. p.s. welcome to the forum! 8-)