'LEAD function with date scenario
I have multiple files, but lets consider 2 files which have filename and start dates columns.
Start_Date | FileName |
---|---|
2022-01-01 | product 1 |
2022-02-02 | product 2 |
please consider both rows as a separate files data.
Now I wanted to generate a dim table which have below requirement. 1st time when I read the file1 I am looking for dim table like below.
Start_date | End_date | file_name |
---|---|---|
2022-01-01 | null | product 1 |
for 2nd time when I read the file I am looking for dim table like below.
Start_date | End_date | file_name |
---|---|---|
2022-01-01 | 2022-02-01 | product 1 |
2022-02-02 | null | product 2 |
basically I want to change the above row null to 2nd file start_date -1
please help
what I am planning, 1st time I am Inserting the data using below query, and 2nd time load also I am using the same query to insert data first then by using Lead function I am planning to update the table
select first_value(Start_date) as EFFECTIVE_START_DATE,
null as End_date,first_value(Source) as SRCE_FILE_NAME from pqdf_view
I am able to write the lead function which is working but How can I update the already inserted column using Lead function. using below query I am able to create a new Column but I want to use the already existing column which is already I inserted using above query data.
select *, LEAD(date_sub(EFFECTIVE_START_DATE,1)) OVER(ORDER BY PRODUCT_QUALITY_SK ASC) as EFFECTIVE_END_DATE from edp_silver.dim_product_quality
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|