I have a table googleplaystore and column Size. I had to remove the last letters from the column Size and I want to drop the old column Size and Save a new one based on case. How do you save a column from case to a new column? I also need to convert values with k (kilobytes) into MB.
SELECT Size,
CASE
WHEN RIGHT(Size,1) = 'k' OR RIGHT(Size,1) = 'M' THEN SUBSTRING(Size,1,LEN(Size)-1)
ELSE 'Varies with device'
END
FROM googleplaystore
1条答案
按热度按时间f0ofjuux1#
You can do it as follows :
to convert from kb to MB in this case you need to divide by 1024.
Input :
Result :
Demo here