mysql为我们提供了两个类型转换函数:CAST和CONVERT,现成的东西我们怎能放过?
1 BINARY[(N)]2 CHAR[(N)]3 DATE4 DATETIME5 DECIMAL6 SIGNED [INTEGER]7 TIME8 UNSIGNED [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