select objectname,
count(*)
from (
select RowNumber,
objectname,
row_number() over(order by RowNumber) - row_number() over(order by objectname, RowNumber) as grp
from rob
where eventclass = 42
) as T
group by grp, objectname
order by min(RowNumber)
テーブル変数を使用した作業サンプル。
declare @T table
(
RowNumber int,
objectname varchar(50)
)
insert into @T values
(8, 'f_system_log_init'),
(10, 'f_purge_system_log'),
(25, 'f_system_log_msg'),
(65, 'f_system_log_msg'),
(104, 'f_system_log_msg'),
(143, 'f_system_log_msg'),
(182, 'f_system_log_msg'),
(221, 'f_system_log_msg'),
(5015, 'f_get_system_logs_parent_log_id_for_dataloader'),
(5055, 'f_system_log_msg'),
(5096, 'f_system_log_msg')
select objectname,
count(*)
from (
select RowNumber,
objectname,
row_number() over(order by RowNumber) - row_number() over(order by objectname, RowNumber) as grp
from @T
) as T
group by grp, objectname
order by min(RowNumber)
結果:
objectname
-------------------------------------------------- -----------
f_system_log_init 1
f_purge_system_log 1
f_system_log_msg 6
f_get_system_logs_parent_log_id_for_dataloader 1
f_system_log_msg 2