按数值对SQL语句中的行进行排序不采用小数


Sorting rows in SQL statement by numeric value is not taking decimals

下面的SQL语句对我的结果进行了正确的排序,但没有考虑小数点。。。我该怎么做?

37.5应该在顶部。

从wp_postmeta中选择*WHERE meta_key="win_percentage"ORDER BY meta_value DESC

Array
(
    [0] => Array
        (
            [meta_id] => 417
            [post_id] => 59
            [meta_key] => win_percentage
            [meta_value] => 9.3023255814
        )
    [1] => Array
        (
            [meta_id] => 419
            [post_id] => 62
            [meta_key] => win_percentage
            [meta_value] => 6.66666666667
        )
    [2] => Array
        (
            [meta_id] => 425
            [post_id] => 64
            [meta_key] => win_percentage
            [meta_value] => 37.5
        )
    [3] => Array
        (
            [meta_id] => 433
            [post_id] => 68
            [meta_key] => win_percentage
            [meta_value] => 36.5079365079
        )
    [4] => Array
        (
            [meta_id] => 421
            [post_id] => 58
            [meta_key] => win_percentage
            [meta_value] => 32.8767123288
        )
    [5] => Array
        (
            [meta_id] => 423
            [post_id] => 63
            [meta_key] => win_percentage
            [meta_value] => 16.6666666667
        )
)

VARCHAR是一个字符串变量类型,所以它就像一个字符串一样排序。6在字符串中位于3之后,因此在对DESC排序时,它将首先出现。

如果您希望将此特定列作为浮点/小数进行排序,您可以使用以下内容:

SELECT * FROM wp_postmeta WHERE meta_key = "win_percentage" ORDER BY CAST(meta_value AS FLOAT) DESC

或者您使用的数据库具有的任何数字类型:http://www.w3schools.com/sql/sql_datatypes_general.asp