在一个论坛的首页,有几个分栏。每个分栏中只显示最新的10条主题标题。数据库有两张表
section(id, name) --栏目id和栏目名称。id自根据序列自增长。
subject(id, title,details,...publishTime, sectionId)
--主题表,publishTime 是date类型。sectionId 是指向section表的外键。id也是根据序列增长。现在希望在进入首页前,只获取每个栏目下最新的10条主题信息。因为这涉及到排序,感觉进入首页的时间比较慢。说明进入首页前获取数据所花的时间比较长,现在有两个问题:1、我怎样获取一个查询结果中的第m到第n条数据?2、我怎样尽量减少进入主页的时间,也就是怎样优化?请高手指点!感激不尽!

解决方案 »

  1.   

    select * 
    from
    (
    select rownum rn,a.*
    from 
    (
    select * from tablename
    where ...
    order by date desc
    ) a
    where rownum <= m
    )
    where rn >= n;
      

  2.   

    1、select * from (select a.*,rownum row_num from (select * from mytable t order by t.id desc) a) b where b.row_num between m and n
    2.缓存OR页面静态化
      

  3.   

    1:使用ORACLE分页可实现
    2:WEB服务器有关
      

  4.   


    select name,title
    from
    (select name,title,rownum rn
    from section a,subject b
    where a.id=b.sectionId
    order by publishTime desc) t
    where rownum between m and n