Java SQL查询使用了大量资源,但没有结果

Java SQL查询使用了大量资源,但没有结果,java,sql,ucanaccess,Java,Sql,Ucanaccess,大家好, 我最近不得不从Access JET引擎转到UcanAccess的引擎,我不太熟悉“标准”SQL查询,也不使用“内部连接”函数。我根据我之前从一个关于DELETE子句的问题中得到的一个答案编写了以下SQL查询,但是这个查询: SELECT TreatmentRecords.DateGiven, TreatmentRecords.TimeGiven, SInformation.Surname, SInformation.FirstNames, SInformation.CampusCode

大家好,

我最近不得不从Access JET引擎转到UcanAccess的引擎,我不太熟悉“标准”SQL查询,也不使用“内部连接”函数。我根据我之前从一个关于DELETE子句的问题中得到的一个答案编写了以下SQL查询,但是这个查询:

SELECT TreatmentRecords.DateGiven, TreatmentRecords.TimeGiven, SInformation.Surname, SInformation.FirstNames, SInformation.CampusCode, TreatmentRecords.Treatment, TreatmentRecords.[AmountGiven], TreatmentRecords.Diagnosis
FROM TreatmentRecords, SInformation
WHERE (((YEAR(TreatmentRecords.DateGiven)) =2015) AND ((MONTH(TreatmentRecords.DateGiven))=03) AND ((TreatmentRecords.SID)<= 70000))
GROUP BY TreatmentRecords.DateGiven, TreatmentRecords.TimeGiven, SInformation.Surname, SInformation.FirstNames, SInformation.CampusCode, TreatmentRecords.Treatment, TreatmentRecords.[AmountGiven], TreatmentRecords.Diagnosis
ORDER BY TreatmentRecords.DateGiven, SInformation.Surname, SInformation.FirstNames;
选择TreatmentRecords.DateGiven,TreatmentRecords.TimeGiven,SinInformation.NorstName,SinInformation.CampuCode,TreatmentRecords.TreatmentRecords.[AmountGiven],TreatmentRecords.Diagnosis
从治疗记录,信息

其中((年(TreatmentRecords.DateGiven))=2015)和((月(TreatmentRecords.DateGiven))=03)和((TreatmentRecords.SID)您的查询执行笛卡尔积(交叉联接)在分组之前,因此可能会详细说明大量的事件,因为您没有指定处理记录和信息之间的任何连接条件


例如,如果您有10000条信息记录和1000条治疗记录,涉及到2015年3月的SID,那么您的查询将执行笛卡尔积(交叉联接)在分组之前,因此可能会详细说明大量的事件,因为您没有指定处理记录和信息之间的任何连接条件


例如,如果2015年3月有10000条信息记录和1000条治疗记录,其中SID更接近jamadei的答案,请尝试使用内部联接来避免笛卡尔乘积的查询:

选择
TreatmentRecords.DateGiven,TreatmentRecords.TimeGiven,
SInformation.姓,SInformation.名,SInformation.CampusCode,
治疗记录。治疗,治疗记录。诊断
从治疗记录内部连接信息
关于TreatmentRecords.SID=SInformation.SID
WHERE TreatmentRecords.DateGiven>=#2015-03-01#
和治疗记录。给出日期<#2015-04-01#

和TreatmentRecords.SID关于jamadei的答案,请尝试使用内部联接来避免笛卡尔积的查询:

选择
TreatmentRecords.DateGiven,TreatmentRecords.TimeGiven,
SInformation.姓,SInformation.名,SInformation.CampusCode,
治疗记录。治疗,治疗记录。诊断
从治疗记录内部连接信息
关于TreatmentRecords.SID=SInformation.SID
WHERE TreatmentRecords.DateGiven>=#2015-03-01#
和治疗记录。给出日期<#2015-04-01#

和TreatmentRecords.SID不包含
TreatmentRecords.SID
包含与
SInformation
中的一列对应的ID值(即
SInformation
中的匹配ID值,它唯一地标识
SInformation
表中的每一行)?Yes.TreatmentRecords.SID=SInformation.SID因此,您只需将TreatmentRecords.SID=SInformation.SID添加到WHERE子句中的条件:…WHERE TreatmentRecords.SID=SInformation.SID和(((YEAR(TreatmentRecords.DateGiven))=2015)和…是否
TreatmentRecords.SID
包含与
SInformation
中的一列对应的ID值(即
SInformation
中的匹配ID值,唯一标识
SInformation
表中的每一行)?Yes.TreatmentRecords.SID=SInformation.SID因此,您只需将TreatmentRecords.SID=SInformation.SID添加到WHERE子句中的条件:…WHERE TreatmentRecords.SID=SInformation.SID和((YEAR(TreatmentRecords.DateGiven))=2015)和。。。