我目前正在按年份连接 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)
最佳答案
快速更改:
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
关于mysql - 使用 concat() 和cast() 按月和年列排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18238098/