0

Each "user_id" has multiple observations with distinct “Status” values.

user_id        status         score      region
  1001         applied         700    california
  1001         pre_approved    700    california
  1001         Approved        700    california

What i am trying to do is having one observation per user_id with flags indicating which "Status" values were observed for the "user_id".

user_id    applied_ind  pre_approved_ind   Approved_ind         score      region
  1001           1                 1               1             700    california

1 Answer 1

2

You can use conditional aggregation:

select user_id,
       max(1) filter (where status = 'applied') as applied_ind,
       max(1) filter (where status = 'pre_approved') as pre_approved_ind,
       max(1) filter (where status = 'approved') as approved_ind,
       score, region
from t
group by user_id, score, region;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.