mysql 字符串函数、分组函数
字符串函数
1、concat 函数
drop table test;
create table test(id int(4), name varchar(10), sex char(2));
insert into test values(1, 'Tom', '男');
select concat(id, name, sex) from test; //查询结果:1Tom男
select concat(id, '-', name, sex) from test; //查询结果:1-Tom男
update test set sex = null;
select concat(id, name, sex) from test; //结果为null, 有一个为null, 结果为null
2、concat_ws 函数
select concat_ws('-', id, name, sex) from test; //结果为1-Tom
第一个参数是其它参数的分隔符;即使有一个结果为null,其它的不为null,结果就不会为null
3、group_concat 函数
drop table test;
create table test (name varchar(10), id int(4));
insert into test values('天',1),('道',2),('酬',3),('勤',4);
insert into test values('天',1),('道',2),('酬',3),('勤',4);
select id, group_concat(name) from test group by id; // 默认逗号分隔
1 天,天
2 道,道
3 酬,酬
4 勤,勤
select id, group_concat(name, '_') from test group by id;
1 天_,天_
2 道_,道_
3 酬_,酬_
4 勤_,勤_
select id, group_concat(name separator'_') from test group by id;
1 天_天
2 道_道
3 酬_酬
4 勤_勤
select id, group_concat(distinct name order by name desc separator '_') from test group by id;
1 天
2 道
3 酬
4 勤
分组函数
select cate_name as catename,count(cate_name) as count from `intl_order_goods` where order_id = 1 group by cate_name
执行结果:

mysql 字符串函数、分组函数的更多相关文章
- Oracle_SQL函数-分组函数
分组函数 什么是分组函数 分组函数作用于一组数据,并对一组数据返回一个值 组函数类型:主要有6种 AVG - 平均 COUNT - 计数 MAX - 最大 MIN - 最小 SUM - 求和 STDD ...
- MySQL 字符串连接CONCAT()函数
MySQL字符串连接函数 使用方法:CONCAT(str1,str2,-) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串, ...
- MySQL 字符串截取SUBSTRING()函数
MySQL 字符串截取相关函数: 1.从左开始截取字符串 left(str, length) 说明:left(被截取字段,截取长度) 例: select left(content,200) as ab ...
- MySQL☞聚合函数/分组函数
分组函数(聚合函数) 1.count(*/列名): a.*:求出该数据的总条数 select count(*) from 表名 b.列名:求出该列中列名不为null的总条数 select cou ...
- mysql字符串的常用函数(截取和拼接)
#截取字符串(先正序取2个,再倒序取1个)SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('aaa-gg-cc-dd','-',2),'-',-1) #获取子表某个字段的 ...
- 025、MySQL字符串大小写转化函数,文本转化大写,文本转化小写
#变大写 SELECT UPPER('abcdABCD123a'); #ABCDABCD123A SELECT UCASE('abcdABCD123a'); #ABCDABCD123A #变小写 SE ...
- mysql基础教程(二)-----分组函数、多表查询、常见函数
分组函数 什么是分组函数 分组函数作用于一组数据,并对一组数据返回一个值. 组函数类型 • AVG() • COUNT() • MAX() • MIN() • SUM() 组函数语法 AVG(平均值) ...
- oracle 分组函数、视图
组函数 分组函数作用于一组数据,对每一组返回一个值 组函数类型: 1.计数 count(列名 或 表达式) 对满足的行数进行统计 2.求和 sum(列名 或 表达式 ...
- oracle_经常使用分组函数
oracle_经常使用分组函数 ①分组函数 1.max(column):求最大值,对数据类型没有要求,随意数据类型都能够 2.min(column):求最小值,对数据类型没有要求,随意数据类型都 ...
随机推荐
- 获取dictionary 值连续相同的索引,
; i < ;) { , i]; var rangType = companyScheme[i]; string txtCell = ""; switch (rangType ...
- (转)权威支持: 选择正确的 WebSphere 诊断工具
权威支持: 选择正确的 WebSphere 诊断工具 原文:https://www.ibm.com/developerworks/cn/websphere/techjournal/0807_supau ...
- (转)http://blog.csdn.net/renfufei/article/details/38474435
原文:http://blog.csdn.net/renfufei/article/details/38474435
- 【Ubuntu】使用记录
Vim 设置自动折行 :set wrap Maven 安装 去官网下载maven安装包 解压maven, 在主目录下的.bashrc中添加 export PATH="$PATH:{your_ ...
- 利用wget配合bash脚本同时下载多个文件
先把需要下载的文件写入到一个文件中,命名为urls.txt,比如: http://blog.is36.com/a.jpg http://blog.is36.com/b.jpg http://blog. ...
- Tomcat 基本配置
1.配置虚拟目录映射 推荐在 /conf/Catalina/localhost 下新建rand.xml方式建立虚拟目录 其中rand将会被当作映射对象,即外部访问路径. 例子:blog.xml < ...
- 【数组】4Sum
题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...
- Python 开发
1.GIL,CPython,Python跟编译器没关系,语言有多个编译器,如:JPython.IronPython等,其他语言如是.GIL对IO密集型友好,计算密集型惨淡 2.pass,定义空执行函数 ...
- Smali 语法文档
可以选择保存成pdf格式,查询起来挺方便的 if v0==0 go cond_0 if-eqz v0, :cond_0 if v0!=0 go cond_0 if-nez v0, :cond_0 ...
- python 笔记-转
python笔记 Python 学习笔记 - 14.技巧(Tips) Python 学习笔记 - 13.异常(Exception) Python 学习笔记 - 12.流程控制(Contro ...