0
我有一個關於從兩天前獲取製造數據的問題。我的代碼工作,但我認爲它對我的實現效率低下。我有這個,獲取最近2天的生產數據
// YESTERDAYS FABRICATION
$yesterdaySql = "SELECT SUM(CURRENT_WEIGHT) AS TOTALYESTERDAYWEIGHT FROM FABRICATION_HIST
WHERE TO_CHAR (FAB_ENTRY_DATE,'MM/DD/YYYY') = TO_CHAR(SYSDATE - 1, 'MM/DD/YYYY')
AND PROJECT_NAME = :projName";
$yesterdayParse = oci_parse($conn, $yesterdaySql);
oci_bind_by_name($yesterdayParse, ":projName", $_SESSION['cd-dropdown']);
oci_define_by_name($yesterdayParse, "TOTALYESTERDAYWEIGHT", $sumWeightYesterday);
oci_execute($yesterdayParse);
// TWO DAYS AGO FABRICATION
$twoDaysSql = "SELECT SUM(CURRENT_WEIGHT) AS TOTALTWODAYSAGOWEIGHT FROM FABRICATION_HIST
WHERE TO_CHAR (FAB_ENTRY_DATE,'MM/DD/YYYY') = TO_CHAR(SYSDATE - 2, 'MM/DD/YYYY')
AND PROJECT_NAME = :projName";
$twoDaysParse = oci_parse($conn, $twoDaysSql);
oci_bind_by_name($twoDaysParse, ":projName", $_SESSION['cd-dropdown']);
oci_define_by_name($twoDaysParse, "TOTALTWODAYSAGOWEIGHT", $sumWeightTwoDays);
oci_execute($twoDaysParse);
我知道這是非常低效的。任何人都可以建議我,這樣我可以在單個查詢中獲取兩天查詢?
在此先感謝
通行證參數,然後只是比較'FAB_ENTRY_DATE'。您也只需要一個參數化查詢。 – fejese 2014-10-09 10:26:23
如果存在性能問題,它最有可能在數據庫本身。一個單一的查詢而不是兩個在這裏不會有太大的影響(在我看來)。您最好要求調整數據庫查詢本身。爲此,我建議您在這裏發佈查詢的執行計劃。 – nop77svk 2014-10-09 10:28:31