I'm writing a SQL script in PostgreSQL and I need to reclassify certain values to a new column that form a label of the values. For example, the values of column A range from 1 to 10 and I want to add a new column B where the values of column A are represented with a label. Stating that values <3 will get the label 'Low' .
I figured out that I need to work with case statements and this is currently my script, but it does not seem to work.
ALTER TABLE 'MyTable' ADD COLUMN 'Labels' varchar(50)
INSERT INTO 'MyTable' ('Labels)
SELECT 'LabelValues',
CASE WHEN 'LabelValues' > X THEN 'Label 1'
WHEN 'LabelValues' > X AND 'LabelValues' <= X THEN 'Label 2'
WHEN 'LabelValues'> X AND 'LabelValues' <= X THEN 'Label 3'
WHEN 'LabelValues'> X AND 'LabelValues'<= X THEN 'Label 4'
WHEN 'LabelValues' <= X THEN 'Label 5'
END
FROM 'MyTable