select EFFECTIVE_DATE,
CCY_CODE,
RATE
from RATE_SHEET
where LOCATION = @loc
and exists(select count(1)
from RATE_SHEET tmp
where tmp.LOCATION = @loc
and tmp.CCY_CODE = MM_CALLRATE_SHEET.CCY_CODE
and tmp.LOAD_DATE > MM_CALLRATE_SHEET.LOAD_DATE
having count(1) < 4)
order by CCY_CODE asc, EFFECTIVE_DATE desc
解析:
AUD 2012-12-12
AUD 2012-12-11
AUD 2012-12-10
AUD 2012-12-09
AUD 2012-12-08
08的记录有4条大于记录, 所以不显示。