我有下面的 sql 语句,最多在 5 分钟内运行。当我向它添加任何连接时,sql 语句会一直运行直到超时。我想知道您是否可以让我知道为什么添加到 sql 语句会导致这种情况?这些是我添加到基本 SQL 的连接:
将此语句添加到 Base SQL
inner join ahsrelate.dbo.ahs_encounter ahs_encounter_1
on AHS_Encounter_1.PatientID=AHS_Patient.ID
或将此语句添加到基本 SQL
inner join AHS_Medication
on ahs_medication.patientid=AHS_Patient.ID
基础 SQL
SELECT distinct
AHS_Patient.FullName,
AHS_Patient_Iorg.OrganizationMrn,
AHS_Patient.SexName,
AHS_Patient.DateOfBirth,
Finding1.NumericResult,
Finding2.NumericResult,
AHS_Problem.ICD9DiagnosisCode,
AHS_Encounter.EncounterDTTM,
AHS_Encounter.EncounterTypeName,
AHS_Result.EntryCode,
AHS_Result_1.EntryCode,
AHS_Result.NumericResult,
AHS_Result_1.NumericResult,
AHS_Result.ClinicalDTTM,
AHS_Result_1.ClinicalDTTM,
AHS_Provider.FullName,
AHS_Problem.Problem,
AHS_Problem.ProblemStatusName,
AHS_Encounter.ApptLocationName,
AHS_Encounter.AppointmentStatusName
FROM AHSRelate.dbo.AHS_Patient AHS_Patient
INNER JOIN AHSRelate.dbo.Finding1 Finding1
ON AHS_Patient.ID=Finding1.PatientID
AND Finding1.EntryMnemonic='BP SYS'
INNER JOIN AHSRelate.dbo.Finding2 Finding2
ON AHS_Patient.ID=Finding2.PatientID
AND Finding2.EntryMnemonic='BP DIAS'
INNER JOIN AHSRelate.dbo.AHS_Result AHS_Result
ON AHS_Patient.ID=AHS_Result.PatientID
AND AHS_Result.EntryCode IN ('D5353078', 'Q25015900')
INNER JOIN AHSRelate.dbo.AHS_Result AHS_Result_1
ON AHS_Patient.ID=AHS_Result_1.PatientID
AND AHS_Result_1.EntryCode IN ('D5353037', 'Q25003000')
INNER JOIN AHSRelate.dbo.AHS_Encounter AHS_Encounter
ON AHS_Encounter.PatientID=AHS_Patient.ID
AND AHS_Encounter.AppointmentStatusName='Pending'
AND AHS_Encounter.EncounterTypeName='Appointment'
and AHS_Encounter.EncounterDTTM >= getdate()-1
and AHS_Encounter.EncounterDTTM <= getdate()+1
INNER JOIN AHSRelate.dbo.AHS_Problem AHS_Problem
ON AHS_Patient.ID=AHS_Problem.PatientID
INNER JOIN AHSRelate.dbo.AHS_Patient_Iorg AHS_Patient_Iorg
ON AHS_Patient.ID=AHS_Patient_Iorg.PersonID
inner JOIN AHSRelate.dbo.AHS_Provider AHS_Provider
ON AHS_Encounter.Provider2ID=AHS_Provider.ID
ORDER BY
AHS_Patient.FullName,
AHS_Result.ClinicalDTTM DESC,
AHS_Result_1.ClinicalDTTM DESC