什么是sql查询,用于查找重复的记录并根据最高计数和降序显示(以降序显示)。
例如:
得到计数可以用
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