add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table tbl
(
Id int identity(1,1)
, Prod varchar(1)
, Id2 int
)
insert into tbl values ('A', 11), ('A', 11), ('A', 11), ('B', 12), ('B', 12), ('A', 13), ('B', 14), ('D', 15)
8 rows affected
select *
, case
when row_number() over (partition by Id2 order by Id) = 1 then 0
else 1
end Flag
from tbl
order by Id
Id Prod Id2 Flag
1 A 11 0
2 A 11 1
3 A 11 1
4 B 12 0
5 B 12 1
6 A 13 0
7 B 14 0
8 D 15 0