I have a table
approval
========
seq
empid
status
Suppose I have 2 records with 开发者_StackOverflowthe 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.
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.
精彩评论