mysql为我们提供了两个类型转换函数:CAST和CONVERT,现成的东西我们怎能放过?
BINARY[(N)]CHAR[(N)]DATEDATETIMEDECIMALSIGNED [INTEGER]TIMEUNSIGNED [INTEGER]
例子:
--使用CAST将varchar转换成int类型排序select server_id from cardserver where game_id = 1 order by CAST(server_id as SIGNED) desc limit 10;--使用CONVERT将varchar转换成int类型排序select server_id from cardserver where game_id = 1 order by CONVERT(server_id,SIGNED) desc limit 10
参考