查詢一級BOM語句SQL

2021-08-30 22:41:22 字數 990 閱讀 6432

原來曾經寫過多級bom語句的查詢,但在實際應用中我們更多的時候是使用到只查詢當前物料的上一級或者下一級物料,這樣我們在使用原來的多級bom語句時效率就相當低了,根據我們平時的查詢,只需簡單寫出一級查詢即可。下面是一級bom查詢的sql語句,平時在各種查詢中非常有用。

select msi.segment1     父物料編碼,

msi.description 父物料說明,

msi1.segment1 子物料編碼,

msi1.description 子物料說明

from mtl_system_items_b msi,

bom_bill_of_materials bom,

bom_inventory_components bic,

mtl_system_items_b msi1

where 1 = 1

and msi.organization_id = 103

and msi.inventory_item_id = bom.assembly_item_id

and msi.organization_id = bom.organization_id

and bom.organization_id = 103

and bom.alternate_bom_designator is null

and bom.bill_sequence_id = bic.bill_sequence_id

and bic.disable_date is null

and bic.component_item_id = msi1.inventory_item_id

and msi1.organization_id = 103

--and msi.segment1 in ('w.pl.rtt.0400.014') --由父及子

and msi1.segment1 in ('yb.h0062') --由子及父

BOM展開SQL語句

示例資料 create table tb 父物料 varchar 10 子物料 varchar 10 insert tb select a1 b1 union all select a1 b2 union all select a1 b3 union all select b1 c1 union a...

mybatis的一級查詢快取

之所以需要查詢快取主要是為了提高查詢訪問速度,就是當使用者執行一次查詢後,會將該資料結果放到快取中,當下次再執行此查詢時就不會訪問資料庫了而是直接從快取中獲取該資料。如果在快取中找到了資料那叫做命中。在mybatis中有一級快取和二級快取兩種快取方式。當乙個 sqlsession 結束後,該 sql...

SQL語句查詢(一)

條件判斷 a case表示式 語法1 select case 字段 when 條件1 then 表示式1 when 條件2 then 表示式2 else 表示式n end語法2 select case when 條件 then 表示式1 else 表示式2 end ex 建表 create tabl...