如何将当前为 varchar 的价格字段转换为小数,以便我的价格能够正确排序?

发布于 2024-08-17 18:46:35 字数 166 浏览 1 评论 0原文

我正在使用MYSQL。

我有一个 varchar 字段,我错误地使用了它的价格。现在,将超过 1000 的任何内容放在列表底部时,该表的排序将无法正常工作。

我猜我需要将现有 POPULATED 数据库中的价格字段从 varchar 转换为十进制?

任何帮助将不胜感激。

I am using MYSQL.

I have a varchar field which i incorrectly used for a price. Now the ordering of this table will not work correctly putting anything over 1000 to the bottom of the list.

I need to convert this price field in an existing POPULATED database from varchar to decimal i guess?

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖兔^ω^ 2024-08-24 18:46:35

只需使用 ALTER TABLE 语句即可。

例如,如果表名为“products”并且字段名为“product_price”,您可以简单地使用:

ALTER TABLE products MODIFY COLUMN product_price DOUBLE;

注意:与任何事情一样,我很想在执行此操作之前对数据进行备份(通过 mysqldump)操作 - 需要几秒钟的时间,安全总比后悔好。 :-)

Simply use the ALTER TABLE statement.

If for example the table is called 'products' and the field is called 'product_price' you could simply use:

ALTER TABLE products MODIFY COLUMN product_price DOUBLE;

NB: As with anything, I'd be very tempted to make a backup of the data (via mysqldump) prior to performing this operation - it'll take seconds and it's always better to be safe rather than sorry. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文