SQL Group by Year

前端 未结 6 951
别那么骄傲
别那么骄傲 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:42

    I don't know about T-SQL, but in SQL in general, what is in the group by clause must exactly match each non-aggregate function column in the select clause. Try

    select CONVERT(varchar,cast(date as datetime),3)
    from shoptransfer 
    where 
    SUBSTRING(productcode, 5, 3) like '%'  group by CONVERT(varchar,cast(date as datetime),3)
    

    also, where SUBSTRING(productcode, 5, 3) like '%' is not filtering out much - maybe remove it.

提交回复
热议问题