每周总更改名称

时间:2014-08-08 02:32:27

标签: sql sql-server

我已经在Microsoft sql server上查看了一周的结果,这是sql代码

SELECT TOP (100) PERCENT CONVERT(varchar, DATEPART(ww, D_Date), 101) AS ReportingWeek,      Proj_name, SUM(Expr1) AS total
FROM     dbo.View_Test_Two
GROUP BY CONVERT(varchar, DATEPART(ww, D_Date), 101), Proj_name
ORDER BY ReportingWeek

每件事情都没关系,但我的问题是周名称


  • 27 data 330736
  • 28 data 117868
  • 29 data 471472
  • 31 data 246468

现在我需要代替27,28,29,31,比如第1周,第2周,第3周......等等

.. 提前谢谢。

1 个答案:

答案 0 :(得分:0)

这样做你想要的吗?

SELECT 'week ' + CONVERT(varchar(255), DATEPART(ww, D_Date) - 26) AS ReportingWeek,
       Proj_name, SUM(Expr1) AS total
FROM  dbo.View_Test_Two
GROUP BY DATEPART(ww, D_Date), Proj_name
ORDER BY min(D_Date);