declare @t table
(
tid int,
tv char(1)
)
insert into @t
select 1,'a' union all
select 1,'a' union all
select 2,'b' union all
select 3,'m' union all
select 4,'b' union all
select 5,'c' union all
select 6,'m' union all
select 7,'v' union all
select 8,'m' union all
select 9,'n'
select distinct *,(select count(1) from @t where tid<=t.tid and tv=t.tv) c
from @t t
本文提供了一个SQL示例,展示了如何创建一个临时表并插入多条记录,最后通过子查询统计特定条件下的记录数量。这对于理解SQL中表操作及聚合函数的使用非常有帮助。
2231

被折叠的 条评论
为什么被折叠?



