2017-02-25 61 views
1

在我的公司,我們實際上是在倉庫之間轉移物料時引用了特定的生產訂單編號。在輸入生產訂單時,在不同工作站之間轉移的物料將顯示爲行。如何在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')) 

傢伙任何幫助嗎?

感謝

回答

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'); 
+0

我已經嘗試過LEFT JOIN和各種JOIN語句,只JOIN和INNER JOIN提供相關的結果,在這種情況下,JOIN語句第二個別名不起作用。請引導我。謝謝 – Ragav

+0

@Ragav。 。 。它怎麼不起作用? –

+0

真的我無法辨認出來。 Mysql在這種情況下奇怪地工作?你能指導我嗎?謝謝 – Ragav