通過建立臨時表得到所需要的輔助資訊,最後邊接主表

2021-04-13 09:26:35 字數 1523 閱讀 3034

select a.*,b.thename productname,b.configname,b.unitname,c.thename storagename,d.storplacename,

b.brandcode brandcode,e.thename brandname,b.modelcode modelcode,f.thename modelname,

l.thename directorname,m.thename operatername,n.thename deptname

into #a from tbselforderitem a

left outer join vdatumproduct b on a.productcode=b.thecode and a.productsortcode=b.productsort

left outer join tbdatumstorage c on a.storagecode=c.thecode

left outer join tbdatumstorageitem d on a.storplacecode=d.storplacecode and a.storagecode=d.storagecode

left outer join tbdatumproductbrand e on b.brandcode=e.thecode

left outer join tbdatumproductmodel f on b.modelcode=f.thecode

left outer join tbselforder g on g.billno=a.billno

left outer join vdatumemployee l on g.directorcode=l.thecode

left outer join vdatumemployee m on g.operatercode=m.thecode

left outer join vdatumdept n on g.deptcode=n.thecode

select a.*,b.thename shopname,b.shopsortname shoptypename,b.companyname companyname,b.belongareaname belongareaname,

c.thename ordermodename,d.thename paymodename,e.*

from tbselforder a

left outer join vdatumshoparea b on a.shopcode=b.thecode

left outer join vselfordermode c on a.ordermodecode=c.thecode

left outer join vselfpaymode d on a.paymodecode=d.thecode

left outer join #a           e on a.billno= e.billno

where a.shopcode in } and e.storagecode in }

drop table #a 

建立索引所需要關注的問題

1 表的主鍵 外來鍵必須有索引 2 資料量超過300的表應該有索引 3 經常與其他表進行連線的表,在連線欄位上應該建立索引 4 經常出現在where子句中的字段,特別是大表的字段,應該建立索引 5 索引應該建在選擇性高的字段上 6 索引應該建在小字段上,對於大的文字字段甚至超長字段,不要建索引 7 ...

Oracle建立臨時表的語法

在oracle8i或以上版本中,可以建立以下兩種臨時表 1。會話特有的臨時表 create global temporary on commit preserve rows 2。事務特有的臨時表 www.2cto.com create global temporary on commit delet...

SQL中臨時表的建立方法

使用臨時表,可以減少sql文的執行次數,提高程式的執行效率。1.物理臨時表 與資料表一樣,在資料庫建立的時候建立,長期存在資料庫中。程式在執行的時候,臨時將資料放入其中,在檢查或者修改完成之後,將其中的資料轉移到其他資料表中。程式結束之後,刪除其中的資料。2.連線式臨時表 與資料庫建立連線的同時建立...