日期:2014-05-16  浏览次数:20692 次

想用一个sql查询点击次数最多的id,怎么写?
SQL code
select *  from (select count(*) cou, t.info_id  from t_visit_logs t  group by t.info_id  order by cou desc) ff where rownum <= 10;

例句十个嵌套查询,只用一个sql是不是可以完成,怎么写。谢谢

------解决方案--------------------
你是想得到cou值最高的10个info_id吗?
如果这样的话,你这条语句应该改改一下吧

select rownum,cou,id from (select count(*) cou, t.info_id as id from t_visit_logs t group by t.info_id order by cou desc) ff where rownum <= 10;

试试吧,我不确定能不能用
------解决方案--------------------
套一层还少了,要两层才行的
SQL code
SELECT cou, info_id
  FROM (SELECT   cou, info_id
            FROM (SELECT   COUNT (*) cou, t.info_id
                      FROM t_visit_logs t
                  GROUP BY t.info_id)
        ORDER BY cou DESC)
 WHERE ROWNUM <= 10