Table Worker
worker_id Salary
1 100000
2 80000
3 300000
4 500000
5 500000
6 200000
7 75000
8 90000
I wish to create another column salary_bin
such that if salary < 80k, then it should be bin 1, if salary is between 80k and 100k, then it will be in bin 2, if salary is between 100k and 300k, then it will be bin3, if salary is between 300k and 500k then it will be bin 4.
Attempt:
alter table dbo.worker
add salary_bin decimal(10,2)
select worker_id, salary,
case when salary>=0 and salary<80000 then salary_bin ='1',
case when salary>=80000 and salary<=100000 then salary_bin ='2',
case when salary>=100000 and salary<=300000 then salary_bin ='3',
case when salary>=300000 and salary<=500000 then salary_bin ='4
from Worker
Error:
Incorrect syntax near '='.
Can someone please help?