Forum Discussion
Semei770
May 06, 2024Copper Contributor
Help with code
I have this code in oracle
if (Income == "NULL") {0}
else if (Emplid == Prior(Emplid) && Income != Prior(Income)) {1}
else if (Emplid != Prior(Emplid) && Income != "Unreported") {1}
else {0}
I did this
SELECT
*,
case
WHEN Income = 'NULL' THEN 0
WHEN LAG(Emplid) OVER (ORDER BY Emplid ASC, Term ASC) = Emplid AND LAG(Income) OVER (ORDER BY Emplid ASC, Term ASC) != IncomeYY THEN 1
WHEN ROW_NUMBER() OVER (PARTITION BY Emplid, Income ORDER BY Term ASC) = 1 THEN 1
WHEN LAG(Emplid) OVER (ORDER BY Emplid ASC, Term ASC) != Emplid AND Income != 'Unreported' THEN 1
ELSE 0
END AS PREVIUOS_INCOME
FROM
Table
It does not work; I appreciate any advice.
It does not work; I appreciate any advice.
- olafhelperBronze Contributor"Does not work" means what in detail? That's really to less on information.
Please post table design as DDL, some sample data as DML statement and the expected result.- Semei770Copper Contributor
Thank you olafhelper
Here is an image about what result I need itEmplid Term IncomeYY Count_Income 1 2213 Unreported 0 1 2237 $35,000 or More 1 1 2237 $35,000 or More 0 1 2243 Unreported 0 1 2243 $35,000 or More 1 1 2245 Unreported 0 - olafhelperBronze Contributor
Here is an image about what result I need itFine,m and what is the source data?
Again, please post table design as DDL, some sample data as DML statement and the expected result.