日期:2014-05-19  浏览次数:20402 次

sql查询语句,获取最近发表过的前三人
id     userid     title       publishdate          
0       1000         123           2007-4-16   9:27
1       1001         456           2007-4-17   9:27
2       1002         789           2007-4-18   9:27
3       1000         789           2007-4-19   9:27
4       1000         312           2007-4-19   10:27

想查询到最近发表过的前三个人,按publishdate降序排序

id     userid     title       publishdate          
4       1000         312           2007-4-19   10:27
2       1002         789           2007-4-18   9:27
1       1001         456           2007-4-17   9:27

------解决方案--------------------
Select
A.*
From
TableName A
Where Not Exists(Select userid From TableName Where userid = A.userid And publishdate > A.publishdate)
Order By publishdate Desc