首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

这种查询该怎么写

2012-01-09 
这种查询该如何写?selectidfrom表where条件orderbyidasc我已经知道id5在查询结果里,我如何知道id5在检索

这种查询该如何写?
select   id   from   表   where   条件   order   by   id   asc
我已经知道id=5在查询结果里,我如何知道id=5在检索结果的第几个?

比如如果检索结果为1   5   8   9,那么id=5在检索结果的第2个.

这个查询该如何写,谢谢!!!

[解决办法]
Select Count(id) From
(select id from 表 where 条件 order by id asc) A
Where id <= 5
[解决办法]
select identity(int,1,1) as id_no,id into #temp from 表 where 条件 order by id asc
select * from #temp where 条件
[解决办法]
select (select count(1)+1 from # where id> a.id) from # a

select id,名次=(select count(1)+1 from # where id <a.id) from # a
where id=5

热点排行