I want to replace values from my table with values from query result. The query looks like this:
select *,
case
when car_model = 'Altima' THEN 'Nissan'
when car_model = 'F-150' THEN 'Ford'
when car_model = 'Civic' THEN 'Honda'
when car_model = 'Silverado' THEN 'Chevrolet'
END
FROM car_sales_data
WHERE car_model IN ('Altima','F-150','Civic','Silverado')
Basically, this is data cleaning task to do. I am working on it for few hours now and I can’t come to any working solution…
**Important thing is that I want these new values to be saved in a table so I can do some analysis afterwards.
**
I’ve tried different things like INSERT INTO, creating table, none of it worked for me. I am a beginner 🙂
>Solution :
update car_sales_data
set car_model=
case
when car_model = 'Altima' THEN 'Nissan'
when car_model = 'F-150' THEN 'Ford'
when car_model = 'Civic' THEN 'Honda'
when car_model = 'Silverado' THEN 'Chevrolet'
else car_model
END
WHERE car_model IN ('Altima','F-150','Civic','Silverado')
Base Data
create table car_sales_data(car_model varchar(100))
insert into car_sales_data values('Altima')
insert into car_sales_data values('F-150')
insert into car_sales_data values('Civic')
insert into car_sales_data values('Civic')