一个表中有个可排序字段,如果要拿出按照这个字段排序后的结果集中某个位置上的值,SQL应该如何写?要求用一个SQL查询来实现。
比如表table字段id从1开始,顺序增长,不一定连续,现在要用一个SQL找出排在正数第5位的记录,SQL应该如何写?
SELECT TOP 1 * FROM (SELECT TOP 5 * FROM yjf ORDER BY ww ASC) DERIVEDTBL ORDER BY ww DESC
--前提是字段中数据不能有重复的
SELECT * FROM yjf a WHERE ((SELECT COUNT(1) FROM yjf WHERE ww < a.ww) = 4)
select id, name from (select ( (select count(table1.id) from table1 where table1.id < table_A.id) + 1 ) as tid, id, name from table1 as table_A) as temp_Table where temp_Table.tid = 5
|