读书人

查询日前有文章更新的文章分类名称SQL

发布时间: 2012-12-17 09:31:40 作者: rapoo

查询最近有文章更新的文章分类名称SQL
有文章分类表和文章表两个表,表结构分别是:

Article
Id CategoryId Title LastUpdatedTime(文章最后更新时间)

Category
Id CategoryName

需要查询出 最近有文章更新的10个 CategoryName

请教大家SQL语句该怎么写? 数据库是SQL Server,谢谢!
[最优解释]
select categoryname from category where id in (select top 10 categoryid from article group by categoryid
order by max(LastUpdatedTime) desc)
[其他解释]

select * from Category where id in
(
select top 10 CategoryId from Article group by CategoryId order by LastUpdatedTime desc
)

[其他解释]
2楼正解,谢谢!

读书人网 >SQL Server

热点推荐