我有一个工作查询,它给了我最大日期:
SELECT a.client_id AS client_id
, a.patientcount AS patientcount
, received_date AS maxRecDate
FROM
(
SELECT DISTINCT CLIENT_ID
, PATIENT_ID
, count(*) over (partition by client_id, patient_id) AS patientcount
from f_accession_daily
) AS a
JOIN F_ACCESSION_DAILY AS f ON a.CLIENT_ID = f.CLIENT_ID
AND a.PATIENT_ID = f.PATIENT_ID
GROUP BY f.RECEIVED_DATE, a.CLIENT_ID, a.patientcount
HAVING f.RECEIVED_DATE = MAX(f.received_date)
在同一个查询中,我还想返回 min(f.received_date)。
有没有办法做到这一点?也许与子查询?