我试图找出在这种情况下如何使用 MAX()。在此查询的结果中,我有重复项,我只想找到一个最新记录(这里是日期:CL.CL_DATE_FROM)并通过 db1.IDF 和 O.IDp 对其进行重复数据删除。
SELECT
db1.IDF as IDF,
O.IDp as IDP,
O.Action as Action,
U.USR_IDENT as Operator,
O.ID_T as ID_T,
OC.OC_MEMO as MEMO,
CONVERT(VARCHAR(10),CL.CL_DATE_FROM,120) as date,
CONVERT(VARCHAR(8),CL.CL_DATE_FROM,108) as time
from OUTBOUND OC
join CALL CL on CL.CL_ID= OC.OC_CL_ID
join CAMPAIGN CA on CA.CA_ID = OC.OC_CA_ID
join STATUSES ATT on ATT.AS_ID = OC.OC_AS_ID
join USERS U on U.USR_ID = OC.OC_USR_ID
join Outbound_Z O on O.ID = OC.OC_CUS_ID
join db1.dbo.Clients db1 on db1.ID_T = O.ID_T
where CL.CL_DATE_FROM BETWEEN '2013-03-05 00:00:00.000' AND '2013-03-05 23:59:59.000'