select a.*, (select count(*) from 表 where col2=a.col2 and col3=a.col3 and ID<=a.ID) from 表 a
select *,aid =identity(int,1,1) into # from tablename select *,(select count(*)+1 from # where id<a.id and col1=a.col1 and col2=a.col2 and col3=a.col3) from # drop table #
--写的是id也一样的情况下的。 select *,aid =identity(int,1,1) into # from tablename select *,(select count(*)+1 from # where aid<a.aid and col1=a.col1 and col2=a.col2 and col3=a.col3) from # drop table #
a.*,
(select count(*) from 表 where col2=a.col2 and col3=a.col3 and ID<=a.ID)
from
表 a
select *,(select count(*)+1 from # where id<a.id and col1=a.col1 and col2=a.col2 and col3=a.col3)
from #
drop table #
select *,aid =identity(int,1,1) into # from tablename
select *,(select count(*)+1 from # where aid<a.aid and col1=a.col1 and col2=a.col2 and col3=a.col3)
from #
drop table #