2012-05-29 138 views
0

我選擇記錄並按日期和uid(這不是主鍵)對它們進行分組,並且我需要按日期對這些記錄進行分頁,我該怎麼辦?
例如:mysql:如何限制查詢?

 
uid date 
1 2012-01-10 
2 2012-01-10 
3 2012-01-09 
3 2012-01-09 
3 2012-01-11 

SQL:

SELECT date, uid 
FROM users 
GROUP by date,`uid` 

結果:

 
uid date 
1 2012-01-10 
2 2012-01-10 
3 2012-01-09 
3 2012-01-11 

因爲我需要頁面按日期的記錄,如果我使用SQL這樣的:

SELECT date, uid 
FROM users 
GROUP by date,`uid` 
LIMIT 0,2 

然後我只是得到這樣的記錄:

 
uid date 
1 2012-01-10 
2 2012-01-10 

。我怎樣才能按日期分頁記錄。 結果我想在頁面大小爲2:

 
uid date 
1 2012-01-10 
2 2012-01-10 
3 2012-01-09 
+0

'LIMIT 0,3' ...... –

回答

1
SELECT date, uid 
FROM users 
WHERE date >= 'your date' 
    AND date < 'your date' LIMIT 0, 3 
+0

但如果我想獲得的10頁的記錄,我怎麼能知道開始日期和結束日期? – remy

+0

Iam不完全確定你的意思 –