Help with code

Copper Contributor

 

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.
3 Replies
"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.

Thank you @olafhelper  

Here is an image about what result I need it

EmplidTermIncomeYYCount_Income
12213Unreported0
12237$35,000 or More1
12237$35,000 or More0
12243Unreported0
12243$35,000 or More1
12245Unreported0

 


Here is an image about what result I need it

 Fine,m and what is the source data?

Again, please post table design as DDL, some sample data as DML statement and the expected result.