1

使用 TSQL - 尝试获取最新的 MAX(HAR_ASSESSMENT.SESSION_DATE) 但我的查询返回的是最旧的评估日期而不是最近的。我认为这与 SERVICE_DELIVERIES 连接和参数有关......任何建议将不胜感激。

**SELECT
  HAR_ASSESSMENTS.NEXT_SESSION_DATE
  ,HAR_CONSUMERS.CLIENT_ID
  ,HAR_CONSUMERS.FULL_NAME
  ,MAX (HAR_SERVICE_DELIVERIES.SERVICE_PERIOD_START) AS Max_SERVICE_PERIOD_START
  ,HAR_SERVICE_DELIVERIES.SERVICE
  ,HAR_ASSESSMENTS.ASSESSFORM_NAME
  ,MAX(HAR_ASSESSMENTS.SESSION_DATE) AS Max_SESSION_DATE
  ,HAR_SERVICE_DELIVERIES.AGENCY
  ,HAR_SERVICE_DELIVERIES.PROVIDER
  ,HAR_SERVICE_DELIVERIES.FUND_IDENTIFIER
FROM
  HAR_CONSUMERS
  INNER JOIN HAR_ASSESSMENTS
    ON HAR_CONSUMERS.CONSUMER_UUID = HAR_ASSESSMENTS.CONSUMER_UUID
  INNER JOIN HAR_SERVICE_DELIVERIES
    ON HAR_CONSUMERS.CONSUMER_UUID = HAR_SERVICE_DELIVERIES.CONSUMER_UUID
WHERE
  HAR_SERVICE_DELIVERIES.SERVICE_PERIOD_START >= @SERVICE_PERIOD_START
  AND HAR_SERVICE_DELIVERIES.SERVICE_PERIOD_START <= @SERVICE_PERIOD_START2
  AND HAR_SERVICE_DELIVERIES.SERVICE IN (@SERVICE)
  AND HAR_ASSESSMENTS.ASSESSFORM_NAME IN (@ASSESSFORM_NAME)
  AND HAR_ASSESSMENTS.AGENCY IN (@AGENCY)
GROUP BY
HAR_ASSESSMENTS.NEXT_SESSION_DATE
  ,HAR_CONSUMERS.CLIENT_ID
  ,HAR_CONSUMERS.FULL_NAME
  ,HAR_SERVICE_DELIVERIES.SERVICE
  ,HAR_ASSESSMENTS.ASSESSFORM_NAME
  ,HAR_SERVICE_DELIVERIES.AGENCY
  ,HAR_SERVICE_DELIVERIES.PROVIDER
  ,HAR_SERVICE_DELIVERIES.FUND_IDENTIFIER**
4

0 回答 0