我用它来获取每周不同RepID的序列号和数量。但不是序列号(1,2,3),我希望序列号值为第1周,第2周,第3周。怎么可能?这是使用SQL Server 2005.谢谢!
Select ROW_NUMBER() OVER (ORDER BY Date) As SlNo, count(distinct(RepID))
from Reptable
where Month(Date) = @Month
group by Datepart(week, Date)
答案 0 :(得分:0)
您需要做的只是将cast()
row_number
作为字符串,然后在其开头连接Week
:
Select
'Week ' + cast(ROW_NUMBER() OVER (ORDER BY Date) as varchar(10)) As SlNo,
count(distinct(RepID))
from Reptable
where Month(Date) = @Month
group by Datepart(week, Date)