I want to update the column 'status' in a dataframe 'Enrollments' that references another 'visitID' column, but I want the values within 'status' to be as follows:
When there are 2 or more Id's that are the same in 'visitID' column - set that value in 'status' as 'returning' and when there is only one unique value in 'visitID' - set that respective value in status as 'new'.
Here is what I tried:
UPDATE Enrollments
SET Status = (CASE WHEN VisitID IS UNIQUE THEN 'New' ELSE 'Returning' END)
I am receiving this error message:
Incorrect syntax near the keyword 'UNIQUE'.
1条答案
按热度按时间o0lyfsai1#
You could make it like this
As you can see the subquery count the occurences of visitID and depending on the number sets the status
fiddle