SQL 多表格查詢語法 |
缺席
|
jacosun
一般會員 發表:42 回覆:64 積分:21 註冊:2003-04-18 發送簡訊給我 |
請問大大們,這樣的寫法執行起來是不是會很慢? 是否有其他的寫法呢?
先謝謝各位大大了~~~ SELECT DPC_PONO AS M_NO, MPC_Frm AS Frm,(SELECT Frm_SName FROM pot_Firm WHERE Frm_ID=MPC_Frm) AS Frm_SName, MPC_Date AS C_Date,MPC_NO AS C_NO, (SELECT C_Date FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS M_Date, DPC_SCT AS SCT,DPC_ECT AS ECT,DPC_Man AS C_Man, (SELECT Emp_CName FROM hrt_Employee WHERE Emp_ID=DPC_Man) AS Emp_CName, (SELECT C_Man FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS M_Man, (SELECT C_MName FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS M_Name, DPC_FLW AS FLW,(SELECT FC_Name FROM qct_FlowClass WHERE FC_ID=DPC_FLW) AS FC_Name, DPC_SUR AS SUR,(SELECT FP_Name FROM qct_FaceProc WHERE FP_ID = DPC_SUR) AS FP_Name, DPC_HPH AS HPH,DPC_CQty AS CQty,(DPC_YQty DPC_NQty) AS Qty,DPC_YQty AS YQty, DPC_NQty AS NQty,EXP_Qty AS EQty,DPC_Mark AS Mark,DPC_EXP AS EXP,EXP_Sta, (Case MPC_Cfm WHEN 0 Then '進行中' ELSE '已完成' END ) AS Cfm, EXP_Duty AS Duty,(SELECT Dept_SName From hrt_Department WHERE Dept_ID = EXP_Duty) AS Dept_SName, EXP_LEX AS LEX,(SELECT LEX_Name From qct_LastExc WHERE LEX_ID = EXP_LEX) AS LEX_Name, DPC_PDID AS PDID,(SELECT Prd_CName FROM stt_Product WHERE Prd_ID=DPC_PDID) AS Prd_CName, (CASE DPC_CKD WHEN 0 THEN '一次檢驗' WHEN 1 THEN '分批檢驗' WHEN 2 THEN '抽樣檢驗' Else '首件檢驗' END) AS CKD, (SELECT C_PName FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS C_PName FROM qct_PCDetail D LEFT OUTER JOIN qct_PCMaster M ON DPC_NO = MPC_NO LEFT OUTER Join qct_Exception E ON DPC_EXP = EXP_NO |
bruce
中階會員 發表:19 回覆:121 積分:83 註冊:2002-04-16 發送簡訊給我 |
|
ace33022
一般會員 發表:2 回覆:41 積分:23 註冊:2004-05-14 發送簡訊給我 |
|
jacosun
一般會員 發表:42 回覆:64 積分:21 註冊:2003-04-18 發送簡訊給我 |
其實我的資料表才398筆,用我上面的語法跑的話 大概要五十八秒才出來的!!
今天閒到發慌就開始找尋原因。我發現....上面的語法有太多(Select .....) as 的 且有重復跟同表格做查詢資料 如: (SELECT C_Date FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS M_Date (SELECT C_Man FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS M_Man, (SELECT C_MName FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS M_Name, (SELECT C_PName FROM qcv_rptCData WHERE C_NO=DPC_CNO) AS C_PName 這四句~~~小弟剛剛把他改了一下 用 join的方式~~~神奇的事發生了 要58秒的查詢時間竟變成短短2秒!! 其實會這樣寫,是記得有人跟我說過用SELECT 方法會比 Join還要快~~ 真不知道啥情狀下該用那個來寫才對 @@!! 不過謝謝兩位大大的回覆囉~~ |
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |