按月汇总,按年汇总,按周汇总 SQL Sever2005
1.按年汇总:
2.按月汇总:
3.按周汇总:
1.按年汇总:
select DATENAME(year,postTime) + '年 ' as [年份],sum(visited) as [AAA],count(title) as [收入]
from t_daily
group by DATENAME(year,postTime) + '年 '
order by DATENAME(year,postTime) + '年 '
2.按月汇总:
select DATENAME(year,postTime) + '年 ' + convert(varchar(2),datepart(month,postTime))+ '月 ' as [时间],sum(visited) as [AAA],sum(dailyId) as [收入]
from t_daily
group by DATENAME(year,postTime) + '年 ' + convert(varchar(2),datepart(month,postTime))+ '月 '
order by DATENAME(year,postTime) + '年 ' + convert(varchar(2),datepart(month,postTime))+ '月 '
3.按周汇总:
select DATENAME(week,postTime) + '周 ' as [周期],sum(visited) as [AAA],count(title) as [收入]
from t_daily
group by DATENAME(week,postTime) + '周 '
order by DATENAME(week,postTime) + '周 '