什么是SQL查询查找重复记录并显示在降序中,基于最高计数和id显示记录.
例如:
可以完成计数
select title,count(title) as cnt from kmovies group by title order by cnt desc
结果就会如此
title cnt ravi 10 prabhu 9 srinu 6
现在查询结果如下所示:
ravi ravi ravi ...10 times prabhu prabhu..9 times srinu srinu...6 times
解决方法
如果您的RDBMS支持OVER子句…
SELECT title FROM ( select title,count(*) OVER (PARTITION BY title) as cnt from kmovies ) T ORDER BY cnt DESC