首页 > 解决方案 > 从表列中的 SQL Server 日期值获取月份名称

问题描述

我想创建一个统计查询(显示每月的记录数)。

问题是我希望月份以字母显示,例如一月、二月、三月等,而不是像 1、2 或 3。我没有使用month(getdate().

我不知道如何进行转换。这是我的 SQL Server 查询:

select count(*) [Total], month(date) [Mois] 
from user 
where year(date) >= 2018 
group by month(date) 
order by month(date) desc 

标签: sqlsql-server

解决方案


你应该尝试这样的事情

select convert(char(3), [date], 0)
select datename(month, [date])

推荐阅读