显示我的ArticleViews表中哪些文章的行数最多(我不知道如何处理)
+-------------------------+---------------------+-----------
| Title ||||||||||||| DateOfView |
+-------------------------+---------------------+-----------
| World Of Warcraft Guide ||||||| 2014-03-17 14:25:00 |
| World Of Warcraft Guide ||||||| 2014-03-07 14:25:00 |
| World Of Warcraft Guide ||||||| 2014-02-25 14:25:00 |
| Leauge Of Legends Guide |||| 2014-03-17 14:25:00 |
| Leauge Of Legends Guide |||| 2014-03-07 14:25:00 |
| The HearthStone Guide ||||||||| 2014-03-17 14:25:00 |
| The HearthStone Guide ||||||||| 2014-03-07 14:25:00 |
| The HearthStone Guide ||||||||| 2014-02-25 14:25:00 |
| The HearthStone Guide ||||||||| 2014-01-01 14:25:00 |
| How to be the best ||||||||||||||||| 2014-03-07 14:25:00 |
| How to tank in WoW ||||||||||||||||| 2014-03-17 14:25:00 |
+-------------------------+-------------------------------------------+
这就是我的表格。
我需要编写一个查询,显示哪个文章的视图最多,我不知道要使用哪个查询。任何建议都将不胜感激。
答案 0 :(得分:2)
以下查询将返回具有最多视图的文章标题。 LIMIT 1
会将查询限制为仅返回1个结果。
SELECT Title, count(*) as count FROM ArticleViews GROUP BY Title ORDER BY count(*) DESC LIMIT 1;
答案 1 :(得分:1)
您的查询可能类似于下面的内容
SELECT Title, count(*) as count FROM ArticleViews GROUP BY Title ORDER BY count DESC;
请注意ORDER BY count DESC
这将按最高视图排序,您可以通过执行ORDER BY count ASC
您可能希望不在列名中使用大写字母,但我想这是个人偏好。
计数
的摘要SQL COUNT函数是最简单的函数,在计算预期由SELECT语句返回的记录数时非常有用。
答案 2 :(得分:1)
试试这个我觉得它有帮助
select count(title) from ArticleViews group by title