简体   繁体   中英

update/fix column datatype and records from string to sort by numeric datatype in mysql innoDB database

I need to remove the last character of every record in the column, that is the "€" symbol and convert the data to some numeric type, bear in mind that the data contains dots in it, as in "20.000€" or "1.000€" or "3.200€" as in the example:

http://i.imgur.com/MZcloPx.png

The idea is to be able to sort the data DESC or ASC, doesn't matter, but it doesnt work now.

What have I tried?

Well I was thinking I could write a python script to do it (i know how) but wondering if there is an easier/faster way to do this...

Thanks!

create a new column in the table, let's call it newfield then do

UPDATE mytable set newfield = CAST(LEFT(oldfield, length(oldfield)-1))

Then drop the new field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM