我试图在 SQL Server 中获取另一个选择的结果集的最大值,但不能。我不确定我在 SQL Server 中做错了什么。任何帮助都会很棒。
这是我的 SQL:
select
max(A.ID), A.Name, A.RMName, A.RName, A.DName, A.Section, A.CF, A.PPV, A.ESD,
A.EED, A.EJ,
A.NJ, A.NAF, A.L4MAF, A.L4MJ, A.MLF, A.PL, A.PN, A.EMSFL, A.PV, A.FName,
A.FLevel, A.SC, A.PID, A.PFID
from (
select distinct
ID, Name, RMName, RName, DName, Section, CF, PPV,
REPLACE(CONVERT (VARCHAR, ESD, 6), ' ', '-') ESD,
REPLACE(CONVERT (VARCHAR, EED, 6), ' ', '-') EED,
REPLACE(REPLACE(REPLACE(EJ, CHAR(10), ''), CHAR(13), ''), CHAR(9), '') as EJ,
REPLACE(REPLACE(REPLACE(NJ,CHAR(10), ''), CHAR(13), ''), CHAR(9), '') as NJ,
NAF,
L4MAF,
REPLACE(REPLACE(REPLACE(L4MJ,CHAR(10), ''), CHAR(13), ''), CHAR(9), '') as L4MJ,
MLF,
PL,
PN,
EMSFL,
PV,
FName,
FLevel,
SC,
PID,
PFID
from
dbo.DFD def (nolock),
dbo.DForm form (nolock),
dbo.DExcp exc (nolock)
where
exc.DPID = def.DFDID
and def.DFID = form.DFID
and NAF = 1
and L4MAF = 1
and RMName is not null
and EED >= GETDATE()
and EED <> '2050-01-01 00:00:00.000') as A
group by
Name, RMName, RName, DName, Section, CF,
PPV, ESD, EED, EJ, NJ, NAF, L4MAF, L4MJ,
MLF, PL, PN, EMSFL, PV, FName, FLevel,
SC, PID, PFID