1。从数据库表中每隔k条记录读一条记录的select语句怎么写啊(设表中有n条信息)?谢谢!2。从数据库表中读取最新的十条记录的select语句怎么写啊(设表中有n条信息)?谢谢!

解决方案 »

  1.   

    1、SQL语句好像比较难,程序筛选比较易。
    2、如果有个自动递增字段:ID,那么
    select top 10 from table order by id desc^_^
      

  2.   

    Dim rsjilu10 As New ADODB.Recordset
    sql = "select top 10 from 纪录 order by 时间 desc"
    rsjilu10.Open sql, cnnjilu, adOpenKeyset, adLockPessimistic
    Set Frmxjt.MSHFlexGrid1.DataSource = rsjilu10不行啊,“保留字错或缺标点”有什么地方错了吗?谢谢
      

  3.   

    select top 10 * from 纪录 order by 时间 desc
      

  4.   

    1。从数据库表中每隔k条记录读一条记录的select语句怎么写啊(设表中有n条信息)?
     dim Rst1 as new adodb.recordset
     rst1.open "select * from 表",Conn,3,3
     dim i as integer
     i=0
     rst1.movefrist
     while (I+1)*K+1)<rst1.recordcount
        rst1.move (i+1)*k+1
        msgbox rst1.fields("字段名").value
        i=i+1
     wend
         
    2。从数据库表中读取最新的十条记录的select语句怎么写啊(设表中有n条信息)?
      <1>如果有自动增长列,可以select * from 表 order by 自动增长列 desc
      <2>如果每有自动增长列,
         rst.open "select * from 表",conn,3,3
         dim cint as integer
         cint=rst.recordcount
         dim i as integer
         for i=1 to 10
            rst.move (cint-10)+i
            msgbox rst.fields("字段名").value
         next i
         以上即可实现,当然,SQL Server 本身也可直接用一条SQl语句取出后若干条的记录,只可惜一时又给忘了.3. "Dim rsjilu10 As New ADODB.Recordset
      sql = "select top 10 from 纪录 order by 时间 desc"
      rsjilu10.Open sql, cnnjilu, adOpenKeyset, adLockPessimistic
      Set Frmxjt.MSHFlexGrid1.DataSource = rsjilu10
      “保留字错或缺标点”
      你这里的SQL语句有错误,应该是:
      sql = "select top 10 * from 纪录 order by 时间 desc"
      里面漏掉一个*号,或者换成你要的某个具体的字段名即可
      

  5.   

    -----------
    --解决第一个问题
    create proc Get_Record
    (
    @K int
    )
    as begin
         select IDENTITY(int,1,1) [id],[name] into #tempTable
         from 你的表名 
         ----------------------------------------------------
         select * from #tempTable
         where 0=([id] % 5)
         order by [id] asc
    end 调用存储过程
    exec get_record 5
      

  6.   

    to : flyingZFX++++++++++++++++++++++++++++++++++++++++++++++
    不好意思,我的表中没有 id 字段,只有类似“姓名”的字段,和“日期”字段 !怎么办?谢谢!
      

  7.   

    rsjilu10.move n 
    本身就可移n条记录
      

  8.   

    to : flyingZFX第一问题,你的程序什么意思啊?看不懂!解释一下吗!
      

  9.   

    --解决第一个问题
    '建立一个名字为Get_Record的存储过程
    create proc Get_Record
    (
    参数 K
    @K int
    )
    as begin
         select IDENTITY(int,1,1) [id],[name] into #tempTable
         from 你的表名 
         '从你的表中将所有的记录添加到一个tempTable中,并添加ID字段
         ----------------------------------------------------
         select * from #tempTable
         where 0=([id] % 5)
         order by [id] asc
         '隔五条返回一条记录 
         '我猜应该是where 0=([id]% @K)
    end 调用存储过程
    exec get_record 5
      

  10.   

    呵呵,,谢谢hicksys(乡下人) 对我的存储过程的解释!!!