declare @tb table(str1 varchar(50))
insert into @tb (str1) values
('Hallway'),
('Hallway'),
('Kitchen'),
('Kitchen'),
('Kitchen'),
('Livingroom'),
('Kitchen'),
('Livingroom'),
('Livingroom'),
('Hallway')
;with cte0(str1,rno)
as
(
select str1, rno=row_number() over(order by (SELECT 1)) from @tb
),
cte1 (str1,rno,pro) as
(
select str1,rno,pno=rno- row_number() over(partition by str1 order by cte0.rno,str1) from cte0
)
select count(*) as cnt, t.str1 from cte0 t inner join cte1 t1 on t.rno=t1.rno group by t.str1,t1.pro order by min(t.rno)