我需要按组合的年周字符串对 SQL Server 2003 上保存的记录进行计数和分组
我被要求绘制 SQL Server 中保存的数据的图表。我可以使用我现有的工具来做到这一点。
但是,我被要求计算数据库中的记录数,根据年份的最后两位数字和周数的组合对它们进行分组,
例如 2011 年的第一周是 1101
例如,2010 年的第十五周将是 1015
(注意需要周为 2 个字符),因此按字母顺序索引 who
我已经尝试了各种组合,例如,
select CASE WHEN DATENAME(ww,j.requestedat) <= 9
THEN (CAST('0' AS VARCHAR(1)) + CAST(DATENAME(ww,j.requestedat) AS VARCHAR(1)))
ELSE CAST(DATENAME(ww,j.requestedat) AS VARCHAR(2))
END AS WeekNumber
, right(DateName(yy, j.requestedat),2) + WeekNumber as YYWW
from
facts_reactive.dbo.jobs j
order by j.requestedat
但都失败了。
任何帮助/指导都感激地接受。
抢
I have been asked to graph data held in SQL Server. This I can do with the tools I have available.
However I have been asked to count the number of records in the database, grouping them based on a combination of last two digits of the Year, and the week number
For example the first week of 2011 would be 1101
example the fifteenth week of 2010 would be 1015
(note need week as 2 char) so index who alphabetically
I have tried various combinations such as
select CASE WHEN DATENAME(ww,j.requestedat) <= 9
THEN (CAST('0' AS VARCHAR(1)) + CAST(DATENAME(ww,j.requestedat) AS VARCHAR(1)))
ELSE CAST(DATENAME(ww,j.requestedat) AS VARCHAR(2))
END AS WeekNumber
, right(DateName(yy, j.requestedat),2) + WeekNumber as YYWW
from
facts_reactive.dbo.jobs j
order by j.requestedat
but all have failed.
Any help/guidance gratefully accepted.
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
try this one :
试试这个:
Try this: