求助一句简单的sql,谢谢!
select link from item where id= '45 '
这样可以查询出3条据库,我现在想查询这3条数据的第2条。请问怎么写?
------解决方案--------------------select xuhao = identity(int,1,1) , link into #temp from item where id= '45 '
select * from #temp where xuhao = 2
------解决方案----------------------方法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)
------解决方案--------------------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
------解决方案--------------------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
------解决方案--------------------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 desc
drop table #tt1
(所影响的行数为 1 行)
link
-----------------
www.google.com
------解决方案--------------------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)