我有一個工作的查詢,讓我的maxDate的最小和最大日期:獲得在同一個查詢
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)
在相同的查詢,我也想回分鐘(f.received_date)。
有沒有辦法做到這一點?也許與子查詢?
,請escpecially提供您表的結構,如果你的問題是所有關於'sql'。它幫助很多。 –
你想把最短日期放在有或選擇? – PseudoToad
@Gizmo我想要能夠返回最大和最小日期 –