根据前一条记录中的值显示记录

发布于 2024-10-20 15:21:04 字数 243 浏览 4 评论 0原文

我有一个表

approval
========
seq
empid
status

假设我有 2 条具有以下值的记录:

(0,10,ok),
(1,20,disabled)

是否有一个 SQL 查询仅在前面的记录的 seq 小于且状态为 ok 时才显示记录。简而言之,我想根据前一条记录中的值显示第二条记录。我是新手,任何帮助都会被接受。

I have a table

approval
========
seq
empid
status

Suppose I have 2 records with the following values:

(0,10,ok),
(1,20,disabled)

Is there a SQL query to display a record only if the record before has seq less than and status as ok. In short I want to display the 2nd record based on values in preceding record. I'm a newbie n any help is accepted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-10-27 15:21:04

SQL(任何变体)中的一个基本概念是各个行只能与其列的值相关。除了特定查询中 ORDER BY 子句的上下文之外,不存在一行位于另一行“之前”或“之后”的情况。在查询结果集之外,数据库可以自由地以它认为合适的任何方式存储行。一个字段中具有“相邻”值的两行可能位于不同的数据库文件中,甚至位于不同的设备上,具体取决于存储层次结构、分区等。即,没有行顺序的概念,除非您使用 ORDER BY 子句强加行顺序。

如果您可以指定“先前记录”在列值方面的含义,那么您的问题就可以得到解答;否则就没有意义。

A fundamental concept in SQL (any variety) is that individual rows can be related only on values of their columns. There is no such thing as one row being "before" or "after" another row except in the context of an ORDER BY clause in a specific query. Outside of a query ResultSet, the database is free to store the rows in any way it sees fit. Two rows with "adjacent" values in one field could be in different database files, even on different devices, depending on the storage hierarchy, partitioning, etc. I.e. there is no concept of row order EXCEPT when you impose one with an ORDER BY clause.

If you can specify what "preceding record" means in terms of column values then your question can be answered; otherwise it makes no sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文