MySQL类型转换

mysql为我们提供了两个类型转换函数:CAST和CONVERT,现成的东西我们怎能放过?

BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL
SIGNED [INTEGER]
TIME
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

参考 http://blog.163.com/jzq_520/blog/static/119311262201171192914788/

上一篇:ArcGIS API for JavaScript 4.2学习笔记[23] 没有地图如何进行查询?【FindTask类的使用】


下一篇:C# mongodb [上]