我有以下数据表格:
基本上,这个表格显示了每个市场每个月的订单和发货信息。在“月份”列中的日期
我想对每个月的每个市场的
输出结果应该是:
我该怎么做呢?我不知道如何这样求和,而且
month marketid totalsold totalshipped lefttoship_thismonth
....
01-01-2015 1 100 50 50
01-01-2015 2 10 3 7
01-01-2015 3 0 0 0
01-02-2015 1 0 50 -50
01-02-2015 2 20 0 20
01-02-2015 3 0 0 0
基本上,这个表格显示了每个市场每个月的订单和发货信息。在“月份”列中的日期
01-01-2015
实际上代表了整个月的Jan 2015
。我想对每个月的每个市场的
lefttoship_thismonth
进行总和,并加上所有之前的月份。这是必要的,因为有人可能在1月份下订单,但在2月份供货。因此,我想知道每个月仍需发运多少物品。输出结果应该是:
month marketid totalsold totalshipped totallefttoship TOTALLEFT
01-01-2015 1 100 50 50 50
01-01-2015 2 10 3 7 7
01-01-2015 3 0 0 0 0
01-02-2015 1 0 50 -50 0 /50-50
01-02-2015 2 20 0 20 27 /7+20
01-02-2015 3 0 0 0 0 / 0+0
我该怎么做呢?我不知道如何这样求和,而且
month
列很难处理。
to_date(month,'dd-mm-yyyy')
而不是month
。 - Gurwinder Singh