我是SQL数据库的新手。我正在尝试进行查询,以便在表格中获得观看次数最多的ArticleID。
ArticleView TABLE:
+----------------+-----------+---------------------+
| ArticleViewNum | ArticleID | ViewDateTime |
+----------------+-----------+---------------------+
| 1 | 2 | 2013-12-01 10:14:00 |
| 2 | 2 | 2012-15-02 12:14:00 |
| 3 | 3 | 2012-16-04 14:01:00 |
| 4 | 4 | 2012-23-06 09:30:00 |
| 5 | 1 | 2012-30-06 01:27:00 |
+----------------+-----------+---------------------+
答案 0 :(得分:2)
以下查询将为您提供浏览次数最多的文章及其查看次数。
select TOP 10 ArticleID, count(*) As ViewCount
from ArticleView Group By ArticleID Order By ViewCount Desc;