--按周统计
SELECT TOP 10
DATENAME(year,AddDate) 年,
DATENAME(week,AddDate) 周,
COUNT(1) 单量,
SUM(total) 总金额,
AVG(total) 客单价
FROM orderinfo t(NOLOCK)
WHERE AddDate BETWEEN '2013-1-1' AND '2014-1-1'
GROUP BY DATENAME(year,AddDate),DATENAME(week,AddDate)
ORDER BY CONVERT(INT,DATENAME(week,AddDate));
----------------------------------------------------------------
--按月统计
SELECT TOP 10
DATENAME(year,AddDate) 年,
DATENAME(month,AddDate) 月,
COUNT(1) 单量,
SUM(total) 总金额,
AVG(total) 客单价
FROM orderinfo t(NOLOCK)
WHERE AddDate BETWEEN '2013-1-1' AND '2014-1-1'
GROUP BY DATENAME(year,AddDate),DATENAME(month,AddDate)
ORDER BY CONVERT(INT,DATENAME(month,AddDate));
----------------------------------------------------------------
--按季度统计
SELECT TOP 10
DATENAME(year,AddDate) 年,
DATENAME(quarter,AddDate) 季度,
COUNT(1) 单量,
SUM(total) 总金额,
AVG(total) 客单价
FROM orderinfo t(NOLOCK)
WHERE AddDate BETWEEN '2013-1-1' AND '2014-1-1'
GROUP BY DATENAME(year,AddDate),DATENAME(quarter,AddDate)
ORDER BY CONVERT(INT,DATENAME(quarter,AddDate));
----------------------------------------------------------------
--按年统计
SELECT TOP 10
DATENAME(year,AddDate) 年,
COUNT(1) 单量,
SUM(total) 总金额,
AVG(total) 客单价
FROM orderinfo t(NOLOCK)
WHERE AddDate BETWEEN '2012-1-1' AND '2014-1-1'
GROUP BY DATENAME(year,AddDate)
ORDER BY CONVERT(INT,DATENAME(year,AddDate));
相关文章
- 01-26SQL篇 语句练习 难度(中等)
- 01-26达梦数据库DM8开启sql日志
- 01-26SQL基础知识V2——JOIN连接
- 01-26sql等值连接,左右连接
- 01-26SQL在xml中的增删改查操作
- 01-26SQL如何求解省市区中的递归问题?
- 01-26SQL优化小讲堂(六)——善待数据库从建表开始
- 01-26SQL练习一--查找最晚入职员工的所有信息
- 01-26牛客在线编程练习:SQL61_较难
- 01-26常用SQL查询语法教程