select id from 
(
select id , rownum row_num from table1 where rowhum <= 40
)
where row_num > 21

解决方案 »

  1.   

    不好意思 有点看不懂 请问row_num 是什么?sql的变量???
      

  2.   

    Some dbms support:Select Top 20 * From tablename Order by columnname
      

  3.   

    那你可以用Stored Procedure 和 Cursor
      

  4.   

    hehe 我对数据库没什么了解 见笑了 我的问题需要在SQL server中解决有哪位大虾知道的请告诉我  还有我用delphi的,如果哪位大哥有同样的开发经验请告诉我 不是用sql语句也无所谓 关键是
    解决分页显示的问题 一个dbgird显示过多数据也不方便看啊
      

  5.   

    可以这样写:
    比如你要取从m条起n条记录:
    select Top n from table where id>(select max(id) from (select top m from table)) 
      

  6.   

    hehe 好办法 就这样了 谢谢苯苯
      

  7.   

    不行啊 语法错误了 不能 select max(id) from (select top m from table)
    好象from后只能接表名有谁能帮我?
      

  8.   

    select max(id) from (select top m id from table)
      

  9.   

    ??????
    from 可以直接接 (select top m id from table) 吗?
    好象不能把???请有人能详细说说
      

  10.   

    我曾经做过类似程序。
    比如FIndex is primary key
    set m_KeyRs = "Select FIndex From <tablename> Order by FIndex "
    set m_DetaiRs = "Select * from <tablename> where FIndex = <FindexValue>"分屏显示:
    <row = From lBeginRow To lEndRow>
    example:
       m_keyrs.movefirst 
       m_KeyRs.move lBeginRow -1    For lIndex = 1 to lEndRow - lBeginRow 
           <...写入FlexGrid显示>
           m_KeyRs.MoveNext
       next
    方案二:
       建立临时表,有一Identity字段,再根据该字段过滤
      

  11.   

    不会吧?至少第一个方案绝对是可以的,我以前做过的。你再试试。
      先取得 m_KeyRs
      在分屏显示时,取得 lBeginRow , lEndRow 
      Call ShowRsGrid(lBeginRow,lEndrow) 
          '手工去填写FlexGrid
          '或者手工新建一个无源的m_TempRs,然后将m_keyrs相应值插入m_TempRs,再Set DBGrid.Recordset = m_temprs
      

  12.   

    不好意思,我写错了。。
    应该是
    select Top n * from table where id>(select max(id) from (select top m id from table))就可以了。
      

  13.   

    如果还不行。
    用下面的
    select Top n * from table where id>(select max(id) from (select top m  from table) as new_table)
      

  14.   

    如果是oracle
    你可以这样写
    select * from (select * from tablename order by id) a where rownum<40
    minus
    select * from (select * from tablename order by id) a where rownum>21
    如果是sql server
    你可以这样写
    select top 20 * from (select top 40 * from tablename order by id) order by id asc
    其实方法很多啊
    如果是变量你可以用
    动态sql
    例如
    俄execute("select top "+convert(varchar(2),@kkk-@kk)+" * from  (select top "+convert(numeric(2,0),@kkk)"+" iid as iiid from tablename order by iid) b order by b.iiid asc");
      

  15.   

    to :magicpower
    类似 Select * from (select * from Table) 这样的查询语句
    支不只支持,与你使用的连接引擎有关!
    如果你是用的Delphi的BDE的话就不支持!
    如果是ODBC的话就可以!!!试试用ODBC设置DNS!
      

  16.   

    sql server 应为:
    select top 20 * from (select top 40 * from tablename order by id)as t1 order by id asc
      

  17.   

    select count(*) table t1
      

  18.   

    在mysql里有limit 字句可用
    其他的不一定有啊