我有这个查询:
declare @startdate datetime='1/1/2012', @endate datetime='12/31/2012'
select * from hours1
where date_start between @startdate and @enddate
我想显示如下数据:
Jan
feb
March
...
December
可以请帮助我如何得到这个?
我有这个查询:
declare @startdate datetime='1/1/2012', @endate datetime='12/31/2012'
select * from hours1
where date_start between @startdate and @enddate
我想显示如下数据:
Jan
feb
March
...
December
可以请帮助我如何得到这个?
我假设您想显示开始日期和结束日期之间的月份。
declare @startdate datetime='1/1/2012',
@endate datetime='12/31/2012'
SELECT
DATENAME(month, date_start)
FROM
hours1
WHERE
date_start between @startdate and @enddate
GROUP BY
DATENAME(month, date_start),
DATEPART(month, date_start)
ORDER BY
DATEPART(month, date_start)
如果要按月汇总数据,请使用日期函数:
select count(<count_grouped_items), sum(<sum_of_grouped_items>), ...
from hours1
where date_start between @startdate and @enddate
group by YEAR(date_start), MONTH(date_start)
order by YEAR(date_start) asc, MONTH(date_starts) asc