SQL语句统计每天、每月、每年的销售总额

一、SQL语句统计每年的销售总额
select year(ordertime) 年,
sum(Total) 销售合计
from 订单表
group by year(ordertime)
二、SQL语句统计每月的销售总额
select year(ordertime) 年,
month(ordertime) 月,
sum(Total) 销售合计
from 订单表
group by year(ordertime),
month(ordertime
三、SQL语句统计每日的销售总额
select year(ordertime) 年,
month(ordertime) 月,
day(ordertime) 日,
sum(Total) 销售合计
from 订单表
group by year(ordertime),
month(ordertime),
day(ordertime)

SQL语句统计每天、每月、每年的销售总额

文章插图
 
mysql查询每天、每周、每月的数据方法
一、查询每天的数据
SELECT
COUNT(1) AS countNumber,
DATE_FORMAT(createTime,'%Y-%m-%d') AS dateTime
FROM
testTable
GROUP BY DATE_FORMAT(createTime,'%Y-%m-%d')
二、查询每周的数据
SELECT
COUNT(1) AS countNumber,
WEEK(createTime) as dateTime
FROM
testTable
GROUP BY WEEK(createTime)
三、查询每月的数据:
SELECT
COUNT(1) AS countNumber,
MONTH(createTime) as dateTime
FROM
testTable
GROUP BY MONTH(createTime)
 

【SQL语句统计每天、每月、每年的销售总额】sql语句包含不包含写法sql语句求和sql语句中有单引号怎么办MYSQL存储过程

    推荐阅读