0

我想计算当前未入院的患者人数(CurrentClinicalInfo = 'False')。ClinicalInfo但是,每个患者有多个s。所以我需要区别对待。

我在下面尝试过这段代码,但它带有太多的列,导致进一步的错误。

 SELECT DISTINCT COUNT(*) AS TableLength
    FROM            PatientDemographics AS p LEFT OUTER JOIN
                             PatientClinicalinformation AS pc ON p.PatientID = pc.PatientID
    WHERE        (pc.PatientID IS NULL) AND (p.FirstName LIKE '%' + + '%') OR
                             (pc.PatientID IS NULL) AND (p.Surname LIKE '%' + + '%') OR
                             (p.FirstName LIKE '%' + + '%') AND (pc.CurrentClinicalInfo = 'False') OR
                             (p.Surname LIKE '%' + + '%
    ') AND (pc.CurrentClinicalInfo = 'False')
4

1 回答 1

1

您想要不同的患者,对吗?

SELECT COUNT(DISTINCT p.PatientID) AS TableLength
FROM PatientDemographics AS p
LEFT JOIN PatientClinicalinformation AS pc ON p.PatientID = pc.PatientID
WHERE pc.PatientID IS NULL AND p.FirstName LIKE '%' + @input + '%'
      OR
      pc.PatientID IS NULL AND p.Surname LIKE '%' + @input + '%'
      OR
      p.FirstName LIKE '%' + @input + '%' AND pc.CurrentClinicalInfo = 'False'
      OR
      p.Surname LIKE '%' + @input + '%' AND pc.CurrentClinicalInfo = 'False'
于 2013-04-03T10:35:35.960 回答