各位玩sql的大神进来看看。

需求:
时间范围2012/02/01-2012/02/05

时间范围2012/02/01-2012/02/05

期初表(截止到2012/01/31的库存)
goods_sn	before_amt
a1		100
a2		50


详细表(2012/02/01-2012/02/05的进出库详细)
goods_sn	type	goods_amt
a1		采购	10
a1		订单	-5
a1		退货	3
a3		采购	100


最后要的结果:

goods_sn	期初	采购	订单	退货	期末
a1		100	10	-5	3	108
a2		50	0	0	0	50
a3		0	100	0	0	100
 

其中不知道type的值有多少种,就是要用动态行转列来做。

需要用mysql实现。mysql不支持full join 可以用union代替。

各位大神帮帮忙。

小弟不胜感激。

猜你喜欢

转载自511930751.iteye.com/blog/1613094