NB
SELECT *,
COUNT(*) OVER(PARTITION BY _2 ORDER BY _1
RANGE BETWEEN 2 PRECEDING AND CURRENT ROW
) -1 AS count
FROM table
ORDER BY ID
Size: a a a
NB
SELECT *,
COUNT(*) OVER(PARTITION BY _2 ORDER BY _1
RANGE BETWEEN 2 PRECEDING AND CURRENT ROW
) -1 AS count
FROM table
ORDER BY ID
NB
t
as (
Select 1
as a,
'a' as b
UNION ALL2
as a,
'b'as b
UNION ALL3
as a,
'a' as b
UNION ALL4
as a,
'a' as b
union all5
as a,
'a' as b
union all6
as a,
'b' as b
)
select *,
count(
*)
over(
partition by b
order by a
range between 2
preceding and current row )
from t
ПФ
NB
NB
ПФ
t
as (
Select 1
as a,
'a' as b
UNION ALL2
as a,
'b'as b
UNION ALL3
as a,
'a' as b
UNION ALL4
as a,
'a' as b
union all5
as a,
'a' as b
union all6
as a,
'b' as b
)
select *,
count(
*)
over(
partition by b
order by a
range between 2
preceding and current row )
from t
NB
2
preceding and current row в данной случае окно без учета партицииПФ
А
2
preceding and current row в данной случае окно без учета партицииNB
NB
ПФ
N
NN
N
AB
N
AS
N
ЕГ