我有超过8000条记录的记录集。我有一个select子句(在where子句中),它将带回10条记录。
正在进行多少次计算?
它相当于搜索80,000(10 x 8000)条记录吗?或者它是64,000,000(8000 x 8000),因为每次它通过它再次搜索整个表来获得子集?
SQL代码如下。该代码的目的是找到过去7天内已关闭的作业,并返回所有相关代码,无论它们是否已打开。
实施例。如果作业S15195昨天关闭,那么它也应该返回X15195,SW15195,W15195C01。
代码可以运行但需要大约30分钟才能运行。然而,由于这将在一夜之间运行并通过电子邮件发送,因此它不应成为问题。
SELECT
JOBHEADER.ORDERNUMBER,
JOBHEADER.ORDERSTATUS,
JOBHEADER.ORDERDESCRIPTION,
JOBHEADER.ORDERDATE,
JOBHEADER.CUSTOMER,
JOBHEADER.JOBACTUALCOSTS,
JOBHEADER.JOBCLOSEDATE,
JOBHEADER.INVOICEDNETTAMOUNT,
JOBHEADER.SALESPERSON,
JOBHEADER.ADDITIONALFIELD_15 AS "PROJECT MANAGER",
Case substring(ORDERNUMBER FROM 2 FOR 1)
when '1' then substring(ORDERNUMBER FROM 2 for 5)
when '2' then substring(ORDERNUMBER FROM 2 for 5)
else substring(ORDERNUMBER from 3 for 5)
End As "PROJECT NUMBER"
FROM JOBHEADER
WHERE
Case substring(ORDERNUMBER FROM 2 FOR 1)
when '1' then substring(ORDERNUMBER FROM 2 for 5)
when '2' then substring(ORDERNUMBER FROM 2 for 5)
else substring(ORDERNUMBER from 3 for 5)
End
IN
(SELECT
Case substring(ORDERNUMBER FROM 2 FOR 1)
when '1' then substring(ORDERNUMBER FROM 2 for 5)
when '2' then substring(ORDERNUMBER FROM 2 for 5)
else substring(ORDERNUMBER from 3 for 5)
End As "PROJECT NUMBER"
FROM JOBHEADER
WHERE DateDiff(Day, JOBHEADER.JOBCLOSEDATE, Cast('NOW' as Date)) <7
)
ORDER BY JOBHEADER.CUSTOMER
select子句中的select子句是否更快或是否与记录搜索量相同?