我有三张table如下:
1/桌“订购水果”
-------------------------------------------------------------
id_fruit_table | fruit_name | order_quantity | delivery_date
---------------+------------+----------------+---------------
1 |mango | 10 | 04 2018
2 |mango | 5 | 05 2018
3 |banana | 20 | 04 2018
4 |pineapple | 9 | 06 2018
2/桌“库存水果”
---------------------------------------------------
id_stock | fruit_name_stock | stock_quantity
--------------+-------------------+----------------
1 | mango | 5
2 | pineapple | 10
3/表“管道”
--------------------------------------------------------------------
id_pipeline | fruit_pipeline | receive_date | pipeline_quantity
--------------+------------------+--------------+-------------------
1 | mango | 04 2018 | 5
2. | banana | 05 2018 | 15
如何进行如下查询/查看/报告:
-----------------------------------------------------------------------------------
fruit | 04 2018 | 05 2018 | 06 2018
---------+---------------------------------------------------------------+---------
| order_qty-| stock-| pipeline | order_qty- | stock- | pipeline | ...
---------+-----------+-------+----------+------------+--------+----------+---------
mango | 10 | 5 | 5 | 5 | 0 | 0 | ...
banana | 20 | 0 | 0 | 0 | 0 | 15 | ...
pineapple| 0 | 10 | 0 | 0 | 10 | 0 | ...
这是开盘存货 05 2018 = 04 2018(stock + pipeline - order_qty)
期初库存 06 2018 = 05 2018(stock + pipeline - order_qty)
1条答案
按热度按时间nnsrf1az1#
试着用下面的方法
您可以使用此信息生成第二个查询
sql小提琴-http://www.sqlfiddle.com/#!9/ceb1680/2号