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