在查询中按月和年格式分组为2017-07

时间:2017-09-30 16:05:17

标签: sql-server datetime group-by

这是我的疑问:

select convert(date, create_timestamp) as date
,sum(count(*)) over (order by convert(date, create_timestamp)) as cumulative
from job_posting jp
group by convert(date, create_timestamp)
order by convert(date, create_timestamp)

按日期分组并显示以下结果:

2015-09-02   1
2015-09-03   2
2015-09-04   5
2015-09-05   7
2015-09-07   14

我想创建一个新查询,以按月和年分组返回结果,如下所示:

2015-09
2015-10
2015-11

我很难找到合适的SQL命令来帮助解决这个问题。这一行造成了问题:

,sum(count(*)) over (order by convert(date, create_timestamp)) as cumulative

1 个答案:

答案 0 :(得分:2)

请注意转换为\documentclass{article} \usepackage{marvosym} \usepackage[bitstream-charter]{mathdesign} \usepackage{geometry} \geometry{ hmargin=1cm, top=5mm, bottom=1mm } \usepackage{hyperref} \hypersetup{ colorlinks=true, urlcolor=blue, linktocpage } \setlength{\parindent}{0pt} \begin{document} {\centering {\huge\bfseries \MakeUppercase{Saksham Sharma}\par} \bigskip {\Large\Letter}{\href{mailto:abc@gmail.com}{abc@gmail.com}}\hfill {\Large\Telefon} +1-xxx-xxx-xxxx\hfill {\Large\Mundus} {\href{example.com}{example.com}} \par} \smallskip Your resume here \end{document}

示例

varchar(7)

<强>返回

Select convert(varchar(7),create_timestamp,23)