Hello
I need help to write the T-SQL with scenario that if room got multiple room_cd and flagged with M and F then room_type will be flagged with majority of M or F like
in 106, with room 1 got 1 to 3 room_cd and flagged with both M and F , but there are 2 M's and 1 F then it should be flagged as MaleMix where as
In room 4 got 1 to 4 room _cd and flagged with 3 F's and 1 M then it should be flagged as FemaleMix,
In room 2 is individual and flagged as M then it should be flagged as Male.
In room 6, flag is null then flagged as 'Any'
`
create table #temp(id int, room int, room_cd varchar(1), flag varchar(1))
insert into #temp values(106,1,'1','M')
insert into #temp values(106,1,'2','M')
insert into #temp values(106,1,'3','F')
insert into #temp values(106,2,'1', 'M')
insert into #temp values(106,3,'1','f')
insert into #temp values(106,4,'1','F')
insert into #temp values(106,4,'2', 'f')
insert into #temp values(106,4,'3','f')
insert into #temp values(106,4,'4','m')
insert into #temp values(106,5,'1', 'M')
insert into #temp values(106,5,'1','M')
insert into #temp values(106,6,'1','')
select * from #temp
create table #temp_result(id int, room int, room_type varchar(15))
insert into #temp_result values(106,1,'MaleMix')
insert into #temp_result values(106,2, 'Male')
insert into #temp_result values(106,3,'FeMale')
insert into #temp_result values(106,4,'FeMaleMix')
insert into #temp_result values(106,5, 'Male')
insert into #temp_result values(106,6, 'Any')
select * from #temp_result`