如何根据行号选择一行? [英] How to select a row based on its row number?

查看:50
本文介绍了如何根据行号选择一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小项目,我需要根据记录的实际行号从临时表中选择一条记录.

I'm working on a small project in which I'll need to select a record from a temporary table based on the actual row number of the record.

如何根据行号选择记录?

How can I select a record based on its row number?

推荐答案

其他几个答案触及了这个问题,但这或许可以解释.SQL(集合论)中确实没有隐含的顺序.所以要提到第五行"需要你介绍一下这个概念

A couple of the other answers touched on the problem, but this might explain. There really isn't an order implied in SQL (set theory). So to refer to the "fifth row" requires you to introduce the concept

Select *
From 
(
    Select 
      Row_Number() Over (Order By SomeField) As RowNum
    , *
    From TheTable
) t2
Where RowNum = 5

在子查询中,通过定义您期望的顺序来创建"行号.现在外部查询能够从有序集合中提取第五个条目.

In the subquery, a row number is "created" by defining the order you expect. Now the outer query is able to pull the fifth entry out of that ordered set.

这篇关于如何根据行号选择一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆