Чтобы вычислить эти категории, вам нужно предварительно вычислить результаты близких строк в «табличном выражении». Например:
select
accountid,
sum(case when cnt > 0 then 1 else 0 end) as cat_a_count,
sum(case when cnt = 0 then 1 else 0 end) as cat_b_count
from (
select
accountid, tim,
( select count(*)
from t b
where b.accountid = t.accountid
and b.tim <> t.tim
and b.tim between t.tim and addtime(t.tim, '00:01:00')
) as cnt
from t
) x
group by accountid
Результат:
accountid cat_a_count cat_b_count
--------- ----------- -----------
1 1 2
2 0 1
Для справки я использовал скрипт данных:
create table t (
accountid int,
tim time
);
insert into t (accountid, tim) values
(1, '12:00'),
(1, '12:01'),
(1, '13:00'),
(2, '14:00');