sqlserver 取日期年份月份

select convert(varchar(10),datepart(YYYY,a.fssj)) as years,--得到年份
convert(varchar(10),datepart(mm,a.fssj)) as months,--得到月份
sum(case when b.fszt in ('1','2') then a.cfs else 0 end) as fscgnumber,
sum(a.cfs) as fsnumber
from T_MTN_Sendrecord a
inner join T_MTN_SendNote b on a.dxdm=b.dxdm
group by convert(varchar(10),datepart(YYYY,a.fssj)),convert(varchar(10),datepart(mm,a.fssj))
order by convert(int,convert(varchar(10),datepart(YYYY,a.fssj))), --年份由字符串转化为数字
convert(int,convert(varchar(10),datepart(mm,a.fssj)))

转载于:https://www.cnblogs.com/miraclesakura/p/4244710.html

你可能感兴趣的:(数据库)