我正在尝试跨三个不同数据库中的三个表运行查询。这个查询有效但我接近十亿条记录......有没有解决方案从smlog.requestor_type和arcust.maj_class中提取以下查询中的不同字段?
SELECT
smreq.request_id AS ROIrequestID,
arcust.customer AS LAWcustID,
smlog.logid AS ESLlogID,
arcust.maj_class AS invoicetype,
smlog.requestor_type AS SMLrequestortype,
smlog.request_type as SMLrequesttype
FROM roi.sm_request_sp_data reqsp
LEFT JOIN smart.smlog@smartlog smlog ON smlog.logid = reqsp.logid
LEFT JOIN roi.sm_requests smreq ON smreq.request_id = reqsp.request_id
LEFT JOIN lawson.arcustomer@smart7 arcust ON arcust.customer =
smreq.customer_id
WHERE smreq.ORIG_DT >= TO_DATE('2016/03/01', 'yyyy/mm/dd')
AND smreq.ORIG_DT <= TO_DATE('2016/03/02','yyyy/mm/dd')
GROUP BY smlog.requestor_type;
答案 0 :(得分:0)
这些是观察,而不是答案
SELECT
smreq.request_id AS ROIrequestID
FROM roi.sm_request_sp_data reqsp
LEFT JOIN roi.sm_requests smreq ON reqsp.request_id = smreq.request_id
WHERE smreq.ORIG_DT >= TO_DATE('2016/03/01', 'yyyy/mm/dd')
AND smreq.ORIG_DT <= TO_DATE('2016/03/02', 'yyyy/mm/dd')
LEFT JOIN被where子句完全覆盖(不允许从左连接产生的任何NULL),所以请改用INNER JOIN。
对于where子句如果您想要一天的数据(&#39; 2016/03/01&#39;)或2天(两者都是&#39),我们不清楚; 2016/03/01&#39; +&#39; 2016/03/02&#39;),如果您只期待一天,那么请不要在第二个谓词中使用&lt; =。
对于其他人,我们确实没有事实依据来提出建议。