SELECT top 10 id, title, Idate
FROM news
ORDER BY Idate DESC如果要查询前 10 到 20 之间的记录应该怎么写呀?

解决方案 »

  1.   

    SELECT top 20 id, title, Idate FROM news 
    where id not in (SELECT top 10 id, title, Idate FROM news ORDER BY Idate DESC)
    ORDER BY Idate DESC
      

  2.   

    SELECT top 10 id, title, Idate FROM news 
    where id not in (SELECT top 10 id, title, Idate FROM news ORDER BY Idate DESC)
    ORDER BY Idate DESC
      

  3.   

    SELECT top 10 id, title, Idate FROM news where id not in (SELECT top 10 id, title, Idate FROM news ORDER BY Idate DESC) ORDER BY Idate DESC
      

  4.   

    没有行号,就是麻烦
    oracle和db2都有行号
      

  5.   

    SELECT top 10 id, title, Idate FROM news 
    where id not in 
    (SELECT top 10 id FROM news ORDER BY Idate DESC)
     ORDER BY Idate DESC
      

  6.   

    select top 10 * from news where id > all(select top 10 id from news order by id) order by id
      

  7.   

    select top 10 id, title, Idate from news where id in
    (SELECT top 10 id, title, Idate
    FROM news
    ORDER BY Idate DESC) order by Idate Desc
      

  8.   

    SELECT top 20 id, title, Idate FROM news 
    where id not in (SELECT top 10 id  FROM news ORDER BY Idate DESC)
    ORDER BY Idate DESC看了你两个问题,感觉你是要做存储过程吧:)
      

  9.   

    SELECT top 20 id, title, Idate FROM news 
    where id not in (SELECT top 10 id, title, Idate FROM news ORDER BY Idate DESC)
    ORDER BY Idate DESC
    上面兄台正解。。就这是分页的思想
      

  10.   

    SELECT top 20 id, title, Idate
    FROM news
    where id not in (select top 10 id from news)
    ORDER BY Idate DESC
      

  11.   

    SELECT top 10 id, title, Idate FROM news 
    where id not in 
    (SELECT top 10 id FROM news ORDER BY Idate DESC)
     ORDER BY Idate DESC
    这个才是正解
      

  12.   

    -----------------------------------------------------------------------------
    方法:先按照顺序取前20条记录,然后在选择的记录基础上倒序取前10条,正好是10-20条记录SELECT TOP 10 *
    FROM (SELECT TOP 20 *
          FROM news
          ORDER BY ID ASC) as a
    ORDER BY ID DESC
    -----------------------------------------------------------------------------------
      

  13.   

    ------------------------------------------------------
    select top 10 id, title, Idate from news where id in
    (SELECT top 20 id FROM news
    ORDER BY Idate DESC) order by Idate Desc
    --------------------------------------------------
      

  14.   

    SELECT TOP 10 *
    FROM (SELECT TOP 20 *
          FROM news
          ORDER BY ID ASC) as a
    ORDER BY ID DESC
      

  15.   

    楼上说的对,不过 not in 实在太耗费资源,大的库就不要用了
      

  16.   

    SELECT TOP 10 *
    FROM (SELECT TOP 20 *
          FROM news
          ORDER BY ID ASC) as a
    ORDER BY ID DESC