日期:2014-05-18 浏览次数:20541 次
SET NOCOUNT ON DECLARE @T TABLE (a VARCHAR(10),b INT) ----------- INSERT @T SELECT 'str1' ,1 INSERT @T SELECT 'str1' ,1 INSERT @T SELECT 'str1' ,1 INSERT @T SELECT 'str2' ,1 INSERT @T SELECT 'str2' ,1 INSERT @T SELECT 'str2' ,1 INSERT @T SELECT 'str2' ,1 INSERT @T SELECT 'str2' ,1 INSERT @T SELECT 'str3' , 1 INSERT @T SELECT 'str3', 1 SELECT A,B=ROW_NUMBER() OVER(PARTITION BY A ORDER BY GETDATE()) FROM @T /**A B ---------- -------------------- str1 1 str1 2 str1 3 str2 1 str2 2 str2 3 str2 4 str2 5 str3 1 str3 2 /
------解决方案--------------------
select a,b=row_number() over(partition by a order by a) from tb