2013-08-27 107 views
0

您好我有下面的查詢返回開始日期表中下一個開始日期的數據,我期望做的是拉數據爲接下來的2個開始日期。任何人都可以幫助我嗎?我編輯過,以顯示我遇到問題的具體部分,而不是提供整個查詢,請記住這是一個子查詢。SQL前2條記錄/值

(a1.expstartdate = (select min(startdate) 
from cstreprts.dbo.startdates 
where startdate+15 > @asofdate and sycampusid = a1.sycampusid) 
    or a1.startdate = (select min(startdate) 
from cstreprts.dbo.startdates where startdate+15 > @asofdate 
and sycampusid = a1.sycampusid)) 
+1

你應該嘗試查詢簡化其最小表達(至少對於這個問題)。 –

回答

2

您可以LIMIT您收到的金額。如果你ORDER BY降序價值LIMIT只會讓你回到你的前2名的結果。

只需ORDER BY然後LIMIT 2

簡單例子

SELECT start_date 
FROM start_date_table 
ORDER BY start_date DESC 
LIMIT 2; 
相關問題