select link from item where id='45'
这样可以查询出3条据库,我现在想查询这3条数据的第2条。请问怎么写?

解决方案 »

  1.   

    select top1 link from item 
    where id='45' 
    and link <>(select top 1 link from item where id='45')
      

  2.   

    select top 1 link from item where id='45'
    and link in(select top 1 link from item)
      

  3.   

    select top 1 link from item where id='45'
    and link not in(select top 1 link from item)--not in
      

  4.   

    这样报错  数据类型 ntext 和 ntext 在 not equal to 运算符中不兼容。link字段的数据类型是 ntext
      

  5.   

    select top 1 link from item where id='45'
    and link not in(select top 1 link from item)这样报错  数据类型 ntext 和 ntext 在 not equal to 运算符中不兼容。link字段的数据类型是 ntext
      

  6.   

    select xuhao = identity(int,1,1) , link into #temp from item where id='45'select * from #temp where xuhao = 2
      

  7.   

    这样好像很麻烦啊,还要插入一个 xuhao  能不能一句 sql 就解决问题的?
      

  8.   

    你的表有主键吗?

    select top 1 * from item where id='45' and (select 主键 from item )>(select 主键 from item where id='45' )
    如果没有就只有建临时表了
    select xuhao = identity(int,1,1) , link into #temp from item where id='45'select * from #temp where xuhao = 2
      

  9.   

    你建一个表 名字叫 item
    字段 
    keyword_id 主键  标识
    id  bigint
    link  ntext数据为
    keyword_id  id     link
    1           45     www.baidu.com
    2           45     www.google.cn
    3           45     www.qq.comselect link from item where id='45'
    这样可以查询出3条数据,我现在想查询这3条数据的第2条。请问怎么写?
      

  10.   

    --方法1.
    select top 1 link from item where id='45' and 
    keyword_id not in(select top 1 keyword_id from item where  id='45' order by keyword_id)--方法2.
    select link from item a where 1=(select count(*) from item where a.id=id and id=45 and a.keyword_id>keyword_id)
      

  11.   

    select link from ( select top 1 * from (select top 2 keyWord_id,link from s2 where id = 45 order by keyWord_id asc )a order by keyWord_id desc) b
    经测试.答案为:
    www.google.cn
      

  12.   

    select top 1 link from (select top 2 link from item where id=45 order by keword_id) a order by a.keyword_id desc
      

  13.   

    select 1 as keyword_id, 45 as id, 'www.baidu.com' as link
    into #tt1
    union all select 2,45,'www.google.com'
    union all select 3,45,'www.qq.com'select top 1 link from (select top 2 keyword_id,link from #tt1 where id=45 order by keyword_id) a order by a.keyword_id descdrop table #tt1(所影响的行数为 1 行)link
    -----------------
    www.google.com
      

  14.   

    select * from item where linke in (select top 2 link from item where id='45' order by 排序字段 ) and  in(select top 2 link from item where id='45' order by 排序字段 desc)