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 :)
2条答案
按热度按时间tgabmvqs1#
Base Data
xriantvc2#
The script below will check if your results table exists, and drop it if so (to allow multiple runs). It then selects the required data into
dbo.test
from your current table, and select the results. I've set it to put the results into a table calleddbo.test
; make sure this name isn't in use already for something else.