MySQL无法正确排序数据

编程入门 行业动态 更新时间:2024-10-27 22:22:14
本文介绍了MySQL无法正确排序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经使用MySQL很长时间了,而且从未遇到过这个问题.我有一个表,用于存储应用程序的分数.出于某种原因,当我按score ASC进行排序时,将首先显示最高得分,而最低得分最后显示.请查看下面的屏幕截图:

I have been using MySQL for a long time and I have never run across this issue. I have a table that stores the scores for an application. For some reason, when I sort by score ASC, the highest score is shown first with the lowest score being last. Please see the screenshot below:

这是我的查询:

SELECT category, subject, max(score) as score FROM scores WHERE customer_id = 1086 AND category = 'Business' GROUP BY subject ORDER BY score ASC

对为什么会发生这种情况有任何想法吗?

Any thoughts on why this is happening?

推荐答案

将score的数据类型从字符串(例如varchar/text)更改为数字(例如int).那应该可以解决排序问题.

Change the datatype of score from string (eg varchar/text) to a number (eg int). That should solve the sorting issue.

当值以字符串形式(按字母顺序)排序时,"60"中的"6"位于"8"之前.

When the values are sorted on string basis (alphabetically), the '6' in '60' comes before '8'.

作为临时解决方法,您还可以尝试order by score+0 asc尝试将您的值转换为数字.

As a temporary work-around you can also try order by score+0 asc to try and convert your value into a number.

更多推荐

MySQL无法正确排序数据

本文发布于:2023-10-28 02:36:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   数据   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!