博问上的一个sql问题
DECLARE @t table(jj varchar(10))
INSERT INTO @t SELECT 'a'
UNION ALL SELECT 'a'
UNION ALL SELECT 'b'
UNION ALL SELECT 'b'
UNION ALL SELECT 'b'
SELECT IDENTITY(INT,1,1) as id,* INTO #t from @t
SELECT *,(SELECT COUNT(0) FROM #t b where a.jj=b.jj and a.id>=b.id) as times FROM #t a
DROP TABLE #t