如何在mysql

时间:2017-02-25 04:10:48

标签: mysql

在我公司,我们实际上是在仓库之间转移材料,参考特定的生产订单编号。输入生产订单时,在不同工作站之间传输的物料将按行显示。

select
    ste.production_order as "Production Order:Link/Production Order:120",
    ste_item.qty as "Qty:Float:60",
ste_item.s_warehouse as "Source Warehouse:Data:120",
    ste_item.t_warehouse as "Target Warehouse:Data:120"

from
    `tabStock Entry` ste INNER JOIN `tabStock Entry Detail` ste_item ON ( ste.name = ste_item.parent and ste.docstatus = 1 and ste.purpose in ('Material Transfer'))

Different warehouses as rows

现在我计划为子表库存条目细节创建别名,以便我可以从第一个别名中选择仓库并添加相邻的仓库,而不是出现在行中,所有内容都会出现在列中。但是为子表显示创建别名没事。

我尝试使用此代码:

select
    ste.production_order as "Production Order:Link/Production Order:120",
    ste_item.qty as "Cutting Qty:Float:60",
    ste_item1.qty as "Forging Qty:Float:60"

from
    `tabStock Entry` ste JOIN `tabStock Entry Detail` ste_item ON ( ste.name = ste_item.parent and ste.docstatus = 1 and  ste_item.t_warehouse in ('Cutting - OMMIFORGE'))

JOIN `tabStock Entry Detail` ste_item1 ON ( ste.name = ste_item1.parent and ste.docstatus = 1 and  ste_item1.t_warehouse in ('Forging - OMMIFORGE'))

伙计们有什么帮助吗?

由于

1 个答案:

答案 0 :(得分:0)

我想你想要left join

select ste.production_order as "Production Order:Link/Production Order:120",
       ste_item.qty as "Cutting Qty:Float:60",
       ste_item1.qty as "Forging Qty:Float:60"   
from `tabStock Entry` ste left join
     `tabStock Entry Detail`
     ste_item 
     on ste.name = ste_item.parent and
        ste.docstatus = 1 and
        ste_item.t_warehouse in ('Cutting - OMMIFORGE') left join
     `tabStock Entry Detail` ste_item1 
     on ste.name = ste_item1.parent and
        ste.docstatus = 1 and
        ste_item1.t_warehouse in ('Forging - OMMIFORGE');