查询最近有文章更新的文章分类名称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楼正解,谢谢!