2
我嘗試在SQL Server中獲得另一個select的結果集的最大值,但無法獲得。我不知道我在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
只是爲了澄清,你是否試圖獲取ID爲最大值的子查詢中行的所有列的值? – Morfie
你是什麼意思,「我不能」?你有錯誤嗎?錯誤的結果? – Lamak
是的,我需要顯示所有行中返回的所有值,並根據結果集我需要顯示一個最大ID,因爲所有其他字段可能在所有其他行中具有相同的數據。 –