我下面的表格有更好的辦法:寫這個SQL
create table ARDebitDetail(ID_ARDebitDetail int identity,
ID_Hearing int, ID_AdvancedRatePlan int)
我試圖讓根據ID_Hearing最新ID_AdvancedRatePlan。最新的意思是最大的ID_ARDebitDetail。我有這個查詢,它工作正常。
select ID_AdvancedRatePlan
from ARDebitDetails
where ID_Hearing = 135878
and ID_ARDebitDetail =
( select max(ID_ARDebitDetail)
from ARDebitDetails
where ID_AdvancedRatePlan > 0 and ID_Hearing = 135878
)
然而,它看起來很醜,聞起來很糟糕。有沒有辦法以更簡潔的方式重寫它?
衛生署。爲什麼我沒有想到這一點。 – AngryHacker 2010-04-10 19:06:17