-- 查询每年数据
select SUM(net_price) AS '总额' FROM `cloud_order` GROUP BY YEAR(from_unixtime(order_time));
select date_format(from_unixtime(order_time),"%Y年") as YEARS,count(id) as count,SUM(net_price) AS '总额' from cloud_order group by YEARS;
-- 查询每月数据
select SUM(net_price) AS '总额' FROM `cloud_order` GROUP BY MONTH(from_unixtime(order_time));
select date_format(from_unixtime(order_time),"%Y年%m月") as MONTHS,count(id) as count,SUM(net_price) AS '总额' from cloud_order group by MONTHS;
-- 查询每周数据
select WEEK(from_unixtime(order_time)) as '时间',SUM(net_price) AS '总额' FROM `cloud_order` GROUP BY WEEK(from_unixtime(order_time));
select date_format(from_unixtime(order_time),"%Y年%m月%d日") as WEEKS,count(id) as count,SUM(net_price) AS '总额' from cloud_order group by WEEKS;
-- 查询每日数据
select SUM(net_price) AS '总额', FROM `cloud_order` GROUP BY DAY(from_unixtime(order_time));
select date_format(from_unixtime(order_time),"%Y年%m月%d日") as DAYS,count(id) as count,SUM(net_price) AS '总额' from cloud_order group by DAYS;
-- 查询季度数据
select concat(from_unixtime(order_time,"%Y"),'-第',floor((from_unixtime(order_time,"%m")+2)/3),'季度') as quarters,count(id) as counts ,SUM(net_price) AS '总额' from cloud_order group by quarters;
-- 时间
select *,from_unixtime(create_time, '%Y-%m-%d %H:%i:%S') as times from table;