当前位置: 代码迷 >> Oracle技术 >> 想用一个sql查询点击次数最多的id,如何写
  详细解决方案

想用一个sql查询点击次数最多的id,如何写

热度:100   发布时间:2016-04-24 08:37:04.0
想用一个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
  相关解决方案