SQL Group by Year

前端 未结 6 926
别那么骄傲
别那么骄傲 2021-01-07 21:09

This is my query.

select CONVERT(varchar, cast(date as datetime), 3)
from shoptransfer 
group by year (date)

I want to group by the year pa

6条回答
  •  隐瞒了意图╮
    2021-01-07 21:36

    How about:

    select datepart(yyyy, [date]) as [year]
    from shoptransfer 
    group by datepart(yyyy, [date])
    

    Or:

    select count(*) as qty, datepart(yyyy, [date]) as [year]
    from shoptransfer 
    group by datepart(yyyy, [date])
    order by [year]
    

    This is based on OP's command: "I want to group by year part of date (varchar) column"

提交回复
热议问题