My data is like:
Desired output:
I have tried using following lines:
CASE WHEN (MINDAY_DIFF > 0) AND (MINDAY_DIFF IS NOT NULL) THEN FIRST_VALUE(BP_MED) OVER(PARTITION BY ID ORDER BY MINDAY_DIFF ASC) END AS DRUG
It gave me NULLS.
I also tried
CASE WHEN (MINDAY_DIFF > 0) THEN BP_MED ELSE NULL END AS DRUG
It gave me both non-null values of BP_MED.
I also tried NVL but that didn’t work as well.
Since it is in Netezza. There are fewer solutions online. Please help.