在 MySql 中将 VARCHAR 转换为 DECIMAL 值
我已将包含字符串值(例如,吃)和浮动值(例如 0.87)的 CSV 文件导入到我的 phpMyAdmin 数据库中的表中.在我处理完所有字符串值并仅保留具有十进制值的行后,我需要将这些值从 VARCHAR 转换为 DECIMAL/FLOAT,以便我可以对该属性执行 MAX().
I have imported a CSV file that contains string values (eg.eating) and floating values (eg. 0.87) into a table in my phpMyAdmin database. After I get ride of all the string values and retain only the rows that have the decimal values, I need to convert such values from VARCHAR to DECIMAL/FLOAT so that I can perform a MAX() on this attribute.
我该怎么做?每次我尝试通过 phpMyAdmin 中的 GUI 执行此操作时,我的所有值都会自动四舍五入为 0 和 1.
How do I do this? Each time I try doing this through the GUI in phpMyAdmin, all my values are automatically rounded off to 0 and 1s.
请帮帮我!
推荐答案
如果您对 MySQL 具有管理员权限,我认为您需要尝试在 MySQL 上执行此类操作.
I think you need to try doing something like this on your MySQL if you have admin privilege on your MySQL.
ALTER TABLE 表名修改列名 DECIMAL(M,D)
ALTER TABLE tablename MODIFY columnname DECIMAL(M,D)
对于 M,D 变量,请阅读 - http://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html
for the M,D variables, read this - http://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html
而且 MySQL 应该能够自动将文本转换为数字.只是 MySQL 中的数据类型可能不是小数,这就是您不能存储任何小数的原因.
And MySQL should be able to automatically converting a text to a numeric. Just that the data type in MySQL might not be a decimal yet that's why you can't store any decimal.
相关文章