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/

MySQL类型转换的更多相关文章

  1. mysql类型转换函数convert与cast的用法

    原文地址:https://blog.csdn.net/kouwoo/article/details/45535733 简单介绍下mysql数据库中用于类型转换的二个函数,convert与cast函数, ...

  2. mysql类型转换函数convert与cast的用法,及SQL server的区别

    首先,convert函数 字符集转换 :   CONVERT(xxx  USING   gb2312) 类型转换和SQL Server一样,不过类型参数上有不同: CAST(xxx  AS   类型) ...

  3. MySQL 类型转换

    1.问题描述 在项目中遇到要将Int类型转为Char类型,然后利用转化后的Char类型进行模糊查询. 例:合同编号在数据库中为int类型 8066 用利用 806 模糊查询出合同编号为8066数据记录 ...

  4. MySQL类型转换 使用CAST将varchar转换成int类型排序

    --使用CAST将varchar转换成int类型排序 select distinct(zone_id) from guild_rank_info order by CAST(zone_id as SI ...

  5. MySQL生成模型

    根据数据库表生成Model using System; using System.Collections.Generic; using System.Data; using System.Text; ...

  6. MySqL触发器以及常用转换函数注意事项

    1,触发器(http://www.cnblogs.com/zzwlovegfj/archive/2012/07/04/2576989.html)       1.MYSQL中触发器中不能对本表进行 i ...

  7. Mysql字符串转换为整型

    使用Convert(字段名, 类型)方法 SELECT CONVERT(filedName, UNSIGNED INTEGER) ;

  8. 安全测试===Mysql 注入技巧学习 MySQL注入技巧(2)

    原文地址:http://websec.files.wordpress.com/2010/11/sqli2.pdf 0x00.介绍 也可以参考瞌腄龙的mysql注入科普:http://drops.woo ...

  9. MySQL- 常用的MySQL函数,指令等

    MySQL查看版本: status: 或者 select version(); //select @@version MySQL昨天, 一周前 ,一月前 ,一年前的数据 这里主要用到了 DATE_SU ...

随机推荐

  1. leetcode 105 Construct Binary Tree from Preorder and Inorder Traversal ----- java

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  2. Metasploit连接postgres数据库

    操作环境为Kali虚拟机 root@kali:~# apt-get install postgresql 启动服务 root@kali:~# service postgresql start [ ok ...

  3. 编码规范(二)之Code Templates的设置(转)

    http://swiftlet.net/archives/1199 编码规范(二)之Code Templates的设置(转) 文件(Files)注释标签:/** * @Title: ${file_na ...

  4. C 语言中 free() 函数简单分析

    又是一个睡不着的夜晚,现在是凌晨03:16,不知道是不是感冒的原因,头脑并不是清醒,但是就是睡不着.摸着黑打开电脑,洗了杯子抓了点茶叶,然后打开饮水机电源.舍友们都睡着了,我戴着耳机听着轻音乐,也能听 ...

  5. java的nio之:java的nio系列教程之channel的数据交换

    在Java NIO中,如果两个通道中有一个是FileChannel,那你可以直接将数据从一个channel(译者注:channel中文常译作通道)传输到另外一个channel. transferFro ...

  6. Concurrent inserts on MyISAM and the binary log

    Recently I had an interesting surprise with concurrent inserts into a MyISAM table. The inserts were ...

  7. Mongo导出数据文件导致错误 Got signal: 6 (Aborted)解决方法

    一哥们要导出一个数据表的数据,结果导出一半,硬盘不够用,卡死了, 然后重启主机,导致mongo启动后进程自动死掉, 报错如下. Mon Oct 28 10:39:02.270 [initandlist ...

  8. qemu-kvm命令

    三种方式创建虚拟机 1.qemu-kvm来创建虚拟机 通过阅读man qemu-kvm手册而清楚的. 于20160430阅读 [root@kvm1 ~]# /usr/libexec/qemu-kvm ...

  9. Android: 在 TextView 里使用删除线

    Android: 在 TextView 里使用删除线 分类: Android2014-09-25 13:17 3431人阅读 评论(0) 收藏 举报 以编程的方式添给 TextView 添加删除线: ...

  10. eclipse开发Android程序sdk和avd的图标不见了

    在eclipse中开发我们的Android程序时,安装sdk是必不可少的,有时候会出现sdk和avd的图标都不见了的情况,一般出现这种情况的原因是你从别处copy了一个sdk的包然后直接在引用造成的, ...