读书人

sql查询语句获取最近发表过的前三人

发布时间: 2012-01-06 22:55:18 作者: rapoo

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

读书人网 >SQL Server

热点推荐