0

我用它来获取每周不同 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)
4

1 回答 1

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)
于 2012-10-16T21:08:33.713 回答