MYSQL中常用的字符串函数
来源:互联网 发布:户型优化设计 编辑:程序博客网 时间:2024/05/17 19:16
MYSQL常用函数
一、常使用函数类型
- 字符串函数
- 数值函数
- 日期函数
- 系统信息函数
(一)字符串函数
1.CONCAT;CONCAT_WS;GROUP_CONCAT
CONCAT(s1,s2,s3,……)
- 连接字符串函数
- 参数中含有null至,连接结果为null
eg:select concat('my','s','ql');
查询结果为mysql
eg:select concat('my','s',null,'ql');
查询结果为null
concat_ws(sep,s1,s2,s3,……)
- 相较concat()函数新增了分割符功能;
- sep分割符不为null值时,查询结果为null;非sep为null值时,该函数自动忽略;
- 分割符是指每两个字符串之间的分割符
eg:select concat_ws('-','0731',23352187,null);
查询结果为:0731-23352187
eg:select concat_ws('null','0731',23352187);
查询结果为:null
eg:select concat_ws('-','0731',23352187,123);
查询结果为:0731-23352187-123
group_concat()
group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
eg:aa表
+------+------+
id | name
|1 | 10|
|1 | 20|
|1 | 20|
|2 | 20|
|3 | 200 |
|3 | 500 |
+------+------+
select id group_concat(name) from aa;
查询结果为:
| id| group_concat(name) |
+------+--------------------+
|1 | 10,20,20|
|2 | 20 |
|3 | 200,500|
+------+--------------------+
3 rows in set (0.00 sec)
select id group_concat(distinct name) from aa group by id;
+------+--------------------+
|1 | 10,20|
|2 | 20 |
|3 | 200,500|
+------+--------------------+
select id,group_concat(name separator ';') from aa group by id;
+------+--------------------+
|1 | 10;20;20|
|2 | 20 |
|3 | 200;500|
+------+--------------------+
select id,group_concat(name order by name desc seperate ';') from aa group by id;
+------+--------------------+
|1 | 20;20;10|
|2 | 20|
|3 | 500;200 |
+------+--------------------+
2.
select
阅读全文
0 0
- mysql中常用的字符串函数
- MYSQL中常用的字符串函数
- MySQL中常用字符串函数
- MySQL中常用字符串函数
- MySQL中常用字符串函数
- MySQL中常用字符串函数
- mysql常用的字符串函数
- 【mysql】mysql中常用的字符串函数,如:replace、cast、concat等函数
- MYSQL:常用字符串函数
- MySQL常用字符串函数
- mysql常用字符串函数
- MySql常用字符串函数
- MYSQL常用字符串函数
- MYSQL中常用的函数
- mysql中常用的函数
- MySQL 常用函数 字符串函数
- MSQL中常用的一些字符串函数
- Sql Server 中常用的字符串函数
- 数据结构-图-邻接多重表的构造(1)
- HiveServer2配置HA
- C语言学习历程(七)数组与指针的程序
- Caused by: java.lang.IllegalArgumentException: Text may not be null
- pycham import random
- MYSQL中常用的字符串函数
- SDUT-2143
- 20171125-1126:java一些基础的学习,没啥说的
- OOP思想和范式编程
- 搭建slave ios平台爆出 org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
- mybatis注解使用
- 【MySql】Sql优化(三)——性能优化
- Python编码错误的解决办法SyntaxError: Non-ASCII character '\xe5' in file
- 源代码寻找分享