I am selecting multiple column from a table, and one of the column i require to fetch record from second row. How should i specify in my query that only that 1 column need to fetch from row 2? The select statement return 2 rows, but segment 4 i need to return 2nd row value only, other column return value of row 1. How should i write it?
select substrb(segment2,1,30) invtime
, substrb(segment3,1,30) invoice
, substrb(segment4,1,10) invdate
from error_process_log;
You can use Anlaytical functions like Lead() Lag() in this scenario. Hope below illustration helps.
SELECT SUBSTR(a.nm,1,10),
SUBSTR(lead(a.sn) over(order by a.sn ),1,5)
FROM
(SELECT 1 AS seq,'avrajit' nm,'Roy1' sn FROM dual
UNION ALL
SELECT 2 AS seq,'shubho' nm,'Roy2' sn FROM dual
UNION ALL
SELECT 3 AS seq,'papa' nm,'Roy3' sn FROM dual
UNION ALL
SELECT 3 AS seq,'romi' nm,'Roy4' sn FROM dual
)a;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.