個人比較喜歡用的鏈表查詢

select distinct b.MaterialID,a.id,a.InNo,a.Title,a.FromType,a.FromBillID,d.orderNo  
 
,a.Executor,h.EmployeeName as ExecutorName,a.Processor,e.EmployeeName as ProcessorName 
 
,a.EnterDate,a.projectID,a.totalProduct 
 
,case a.billStatus when '0' then '制單' when '1' then '執行' when '2' then'結單' end as b illStatus 
 
,a.DepId,f.CustName,b.ID as detailID,b.ProductNo,b.ProductName,b.Specification,b.size 
 
,b.unit,b.StorageID,c.StorageName,b.StorageDID,sd.ProductCount,c.StorageDName 
 
,b.ProductCount,b.procedureNO,b.arts,b.RunCard,b.RuncardStatus 

 from officedba.OutSourceInfo a 

 left join officedba.OutSourceDetail b on a.InNo=b.InNo 

 left join officedba.StorageDetailInfo c on c.ID=b.StorageDID and c.StorageNo=b.StorageID 
 left join officedba.PurchaseOrder d on a.FromBillID=d.OrderNO 

 left join officedba.EmployeeInfo e on e.ID=a.Processor 

 left join officedba.ProviderInfo f on f.ID=a.DepId 

 left join officedba.EmployeeInfo h on h.ID=a.Executor 

 left join officedba.ProductInfo i on b.ProductNo=i.ProdNo 

 left join MaterialDetailInfo j on j.MD03=i.ID 

 left join officedba.CodeUnitType cu on cu.ID=b.Unit 

 left join officedba.TechnicsArchives ta on ta.TechNo=b.arts 

 left join officedba.RunCardDetail sd on sd.runcard=b.runcard  
 and sd.ProcedureID=b.procedureNO 

 where a.InNo='CKDBH2017040060'

之前寫過一個關聯查詢和子查詢效率對比的博客,流露出自己對關聯查詢的青睞,如果邏輯足夠清晰,關聯查詢是一個不錯的選擇。上面是自己剛寫的一個關聯查詢的sql語句,拿出來曬曬,總覺得有一兩米長)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章