mysql根据月份查询订单销售额
这样的样式,查出
这样的效果
代码如下:下面是连表查询的
select year(o.order_create) yy,month(o.order_create) mm,sum(ol.good_money)
as value from erp_goods_type gt,erp_goods g,erp_order_list ol,erp_order o
where gt.t_id=g.t_id and g.g_id=ol.good_id and ol.order_id=o.order_id
GROUP BY year(o.order_create),month(o.order_create)
参考代码
select
sum(Omoney) as Omoney,
year(odate) as yy,
month(odate) as mm
from yourtable
group by year(odate),month(odate)
order by year(odate),month(odate)
年份截取
select DISTINCT SUBSTRING(order_create,1,4) from erp_order;