使用concat()和cast()按月和年份排序

时间:2013-08-14 17:14:08

标签: mysql sql

我目前正在按年份连接每月的month_volunteer_ccyy和monthly_volunteer_month列,大概将结果转换为字符串。然后将其命名为int以获得由ccyymm排序的结果集。

不知何故,它会在INT)附近抛出错误。我能做些什么来让它发挥作用? 也指出了清洁方式的奖励积分。

SELECT *
FROM monthly_honorarium_processing
ORDER BY cast(CONCAT (
        monthly_volunteer_ccyy
        ,monthly_volunteer_month
        ) AS INT)

1 个答案:

答案 0 :(得分:2)

快速更改:

SELECT *
FROM monthly_honorarium_processing
ORDER BY cast(CONCAT (
        monthly_volunteer_ccyy
        ,monthly_volunteer_month
        ) AS DECIMAL)

这不能正确处理monthly_volunteer_month< 10

为什么不这样做:

SELECT *
FROM monthly_honorarium_processing
ORDER BY
        monthly_volunteer_ccyy
        ,monthly_volunteer_month