发布网友 发布时间:2024-01-19 00:00
共1个回答
热心网友 时间:2024-07-21 13:42
一、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)
扩展资料
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语句大全