mysql显示指定日期范围的每日数据

时间:2017-01-18 10:42:12

标签: mysql

查询: - 过去7天内显示customername,total_return,过去7天内quantity_sold显示给客户 每天代表一个专栏,如下所示,我做了前3列。

但我不知道如何显示每个特定日期或日期的数据。

customername        total_retuns    total_sold   t_6 t_5 t_4 t_3 t_2 t_1 t
---------------------------------------------------------------------------------
karan       |        80            |   200      |   |   |   |   |   |   |   |
hemanth     |        90             |  300                          
--------------------------------------------------------------------------------

选择查询:

select c.Name,sum(od.return_quantity) totalReturns,
       sum(od.quantity_sold) quantitySold from customer c

left join orders o on c.CustomerId=o.CustomerId

left join order_details od on o.OrderId=od.orderid

where o.OrderedDate between curdate()-6 and curdate()
      group by c.Name order by totalreturns;

0 个答案:

没有答案