mysql常用函数小结
来源:互联网 发布:零售超市收银软件 编辑:程序博客网 时间:2024/04/30 16:45
1、substring_index(str,delim,count)
str:要处理的字符串
delim:分隔符
count:计数
例子:str=www.google.com
substring_index(str,'.',1)
结果是:www
substring_index(str,'.',2)
结果是:www.google
也就是说,如果count是正数,那么就是从左往右数,第N个分隔符的左边的全部内容
相反,如果是负数,那么就是从右边开始数,第N个分隔符右边的所有内容,如:
substring_index(str,'.',-2)
结果为:google.com
有人会为,如果我呀中间的的google怎么办?
很简单的,两个方向:
从右数第二个分隔符的右边全部,再从左数的第一个分隔符的左边:
substring_index(substring_index(str,'.',-2),‘.’,1);
2,concat是连接几个字符串。
concat('wo','lin','xue','bin')
结果就是wolinxuebin。
3, group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果。
语句 SELECT locus,GROUP_CONCAT(id) FROM info WHERE locus IN('AB086827','AF040764') GROUP BY locus; 的返回结果为
+----------+------------------+
| locus | GROUP_CONCAT(id) |
+----------+------------------+
| AB086827 | 1,2 |
| AF040764 | 23,24 |
+----------+------------------+
语句 SELECT locus,GROUP_CONCAT(distinct id ORDER BY id DESC SEPARATOR '_') FROM info WHERE locus IN('AB086827','AF040764') GROUP BY locus;的返回结果为
+----------+----------------------------------------------------------+
| locus | GROUP_CONCAT(distinct id ORDER BY id DESC SEPARATOR '_') |
+----------+----------------------------------------------------------+
| AB086827 | 2_1 |
| AF040764 | 24_23 |
+----------+----------------------------------------------------------+
语句SELECT locus,GROUP_CONCAT(concat_ws(', ',id,journal) ORDER BY id DESC SEPARATOR '. ') FROM info WHERE locus IN('AB086827','AF040764') GROUP BY locus;的返回结果为
+----------+--------------------------------------------------------------------------+
| locus | GROUP_CONCAT(concat_ws(', ',id,journal) ORDER BY id DESC SEPARATOR '. ') |
+----------+--------------------------------------------------------------------------+
| AB086827 | 2, Submitted (20-JUN-2002). 1, Unpublished |
| AF040764 | 24, Submitted (31-DEC-1997) . 23, Unpublished |
+----------+--------------------------------------------------------------------------+
- mysql常用函数小结
- Mysql常用语句小结
- MySQL常用语句小结
- MySQL常用数据类型小结
- 小结Mysql常用快捷键
- mysql小结常用知识点
- MySQL 常用指令小结
- STL常用函数小结
- 常用函数小结
- php常用函数小结
- PHP常用函数小结
- mysql系统函数小结
- VB常用功能函数小结
- 小结下常用的函数
- Oracle 常用的函数小结
- Oracle 常用的函数小结
- C学习小结【常用函数】
- PHP常用字符串函数小结
- 形态学操作
- android ListView 添加 HeaderView 和 FooterView时 不可选择点击
- [python] 优雅的操作字典
- 使用json协议传输二进制文件
- Android常用控件:ListView(2)
- mysql常用函数小结
- 原码, 反码, 补码 详解
- Java 并发工具包 java.util.concurrent 大全
- 大数据的处理方法<一>
- MongoDB简介
- AngularJs ui-router 路由的简单介绍
- 【HUSTOJ】1014: 三个数比大小
- sql统计表个数以及表中字段个数
- 我常用的 Python 调试工具