We need to compare two successive records of a table based
on a field. For example, if the table is CUSTOMER, and the
filed is Account_ID, To compare Account_IDs of record1 and
record2 of CUSTOMER table, what can be the query ?
Answers were Sorted based on User's Feedback
Answer / garima
SELECT (case when a_id > b_id then 'Greater' else 'Lesser'
end), a_id, b_id
FROM (SELECT ROWNUM r_a, account_id a_id
FROM customer) a,
(SELECT ROWNUM r_b, account_id b_id
FROM customer) b
where r_a = r_b+1;
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / suman rana
select * from
(SELECT account_id , lead(account_id, 1, 0) over (order by
1) nxt_account_id FROM customer)
where account_id = nxt_account_id
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manikandan. s
WITH wt AS
(SELECT ROWNUM sl, a.Account_ID
FROM CUSTOMER a)
SELECT a1.*
FROM wt a1, wt a2
WHERE a1.sl = a2.sl + 1 AND a1.col1 = a2.col1
UNION
SELECT a2.*
FROM wt a1, wt a2
WHERE a1.sl = a2.sl + 1 AND a1.col1 = a2.col1
| Is This Answer Correct ? | 1 Yes | 2 No |
How to add a new column to an existing table with a default value?
How many types of segments in Oracle?
What is cursor
I know that i can create a table without a primary key.But is there any significance for that table???? while creating an application.
What is an oracle database?
How to create a new table by selecting rows from another table?
How to define a variable of a specific record type?
Who i will insert 1 lacks record in a Database table
How to use an explicit cursor without open statements?
what are the disadvantages of hierarchial database over RDBMS?
Explain what are synonyms used for?
What are dml statements in oracle?