现在有一个表  表名为info我现在想做分页
当前的语句是这个样子的select top 30 * from info where id not in(select top 30 id from info)and id is not null这个语句是没有问题  但是我想排序一下 让先发帖的人在最上面  我用了order by fbtime desc  但是由于我现在用了top 30  所以排序完全的乱了   请大家帮个忙 这个sql语句应该怎么排序

解决方案 »

  1.   

    select * from (
    select top 30 * from info where id not in(select top 30 id from info)and id is not null 
    ) t order by fbtime desc  
      

  2.   

    select *
    from 
    (
    select top 30 * from info where id not in(select top 30 id from info)and id is not null 
    ) t
    order by fbtime desc 
      

  3.   

    慢了17s,帮楼主改个括号:select *
    from 
    (
    select top 30 * from info where id not in(select top 30 id from info) and id is not null 
    ) t
    order by fbtime desc 
      

  4.   

    [code=SQLselect top 30 * from info where id not in(select top 30 id from info)and id is not null 
    order by 字段
    ][/code]
      

  5.   


    select top 30 * from info where id not in(select top 30 id from info)and id is not null 
    order by 字段 desc
      

  6.   

    select * from 
    (
     select top 30 * from info where id not in(select top 30 id from info)and id is not null 
    ) t 
    order by fbtime desc  
      

  7.   


    --sql2000
    select * from 
    (
        select *,Rn = (select count(1) from info where fbtime < a.fbtime) 
        from fbtime a
    )t
    where Rn between 40 and 60
    order by rn
    ---sql 2005
    select * from 
    (
        select *,Rn = row_number() over (order by fbtime desc)
        from fbtime a
    )t
    where Rn between 40 and 60
    order by rn
      

  8.   


    我知道这样可以排序   但是我的意思是 如何让info这个表的数据在查询之前就排序好  也就是说select top 30 * from (select * from info order by fbtime desc)大家都误会了 可能是我表达的不好 小弟刚学  不好意思了   
      

  9.   

    如果info这个表的数据排序好了 用我刚才的这句select top 30 * from info where id not in(select top 30 id from info)and id is not null  就没问题了
      

  10.   

    select * from
    (
      select *,row_numner() over(order by fbtime desc) rank from info 
    ) T where rank<30
      

  11.   

    没有完全明白楼主的意思,猜一个
    select 
      top 30 
      * 
    from 
      info 
    where 
      id not in(select top 30 id from info order by id)
    and 
      id is not null  
    order by
      fbtime desc
      

  12.   


    select top 30 * from (select * from info order by fbtime desc) 
    --select top 30   * from info order by fbtime desc
      

  13.   


    select top 30 * from (select top 100 percent * from info order by fbtime desc) t这样?
      

  14.   

    如果是那样,就等于以下那样了:
    select top 30  * from info order by fbtime desc
      

  15.   


    public class readPro
    {
       
        public static void main(String[] args) throws IOException
        {
            Properties pro = new Properties();
            FileInputStream fis = new FileInputStream("pro.properties");
            pro.load(fis);
        }}
      

  16.   


     Private Sub TmSendStatusRequest_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles TmSendStatusRequest.Elapsed
            TmSendStatusRequest.Stop()
            Dim ReturnValue As Boolean = False
            Try
                If (IsConnected = True) Then
                    ReturnValue = StatusRequest()
                    Exit Try
                End If
            Catch ex As Exception
                EventLog.WriteEntry("PVGAFDS\TmSendStatusRequest_Elapsed", ex.Message.ToString() + Constants.vbCrLf + ex.StackTrace.ToString(), EventLogEntryType.Error)
            Finally
            End Try
            TmSendStatusRequest.Start()
        End Sub