i only have three rows of date but i need to have four as my output. How do i tell sql to get the last data for the end date and place it in the last row of the start date?
i tried the lag and lead but it seems it does not work in Teradata database i don't know why.
any suggestion will really help or alternative. Just as ask for any clarification or if you need more data.
One possible option: take the set of records of interest, number each row, then self join each row with the following one. Add an extra record for your closing:
WITH numbered AS (
SELECT effect_date, row_number() OVER (ORDER BY effect_date) AS rownum
FROM price
WHERE prod_id='4'
)
SELECT *
FROM ( SELECT a.effect_date AS start_date
,b.effect_date AS end_date
FROM numbered a
,numbered b
WHERE b.rownum = a.rownum + 1
UNION
SELECT MAX(effect_date)
,TO_DATE('29991231', 'YYYYMMDD')
FROM numbered
) x
ORDER BY 1
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.