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):求最小值,对数据类型没有要求,随意数据类型都 ...
随机推荐
- python基础笔记之面向对象
# class Foo:# name="kevin"## def __init__(self,puppy):# self.tomato= 'red'# self.dog = pup ...
- 【链表】Partition List
题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...
- 如何在虚拟机安装的Win10系统里快速打开【此电脑】图标?(图文详解)
不多说,直接上干货! 为什么要写写这篇博客? 技多不压身,很多小技巧很重要,方便自己. 比如,对于这样的工具,个人来讲,玩过试用期,意味着你若不找点法子,是不行的.否则你没得玩了. 全网最详细的Tab ...
- Python -- Gui编程 -- Qt库的使用 -- 配置资源文件
1.源文件(qtRes.py) import sys from PyQt4 import QtCore, QtGui, uic class MyDialog(QtGui.QDialog): def _ ...
- Selenium Web自动化 原理
文章转自 白月黑羽教Python 原理 说到web应用自动化测试,第一选择就是 Selenium 框架. Selenium 是一个 Web 应用的自动化框架. 通过它,我们可以写出自动化程序像人一样( ...
- 4-nginx-反向代理到tomcat及负载均衡
反向代理相比于正向代理, 比如使用搬瓦工时, 就是位于客户端的正想代理, 而反向代理则是服务器端的代理, 主要用于实现请求分发, 负载均衡等功能 正向代理推荐一个: 搬瓦工, 比较好用.. 反向代理主 ...
- Java并发编程笔记之ThreadLocalRandom源码分析
JDK 并发包中 ThreadLocalRandom 类原理剖析,经常使用的随机数生成器 Random 类的原理是什么?及其局限性是什么?ThreadLocalRandom 是如何利用 ThreadL ...
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
什么是ApplicationContext? 它是spring的核心,Context我们通常解释为上下文环境,但是理解成容器会更好些. ApplicationContext则是应用的容器. Sprin ...
- mongodb带认证的副本集搭建
Mongodb副本集带用户认证的 概述 本次实验是在一台虚拟机上做的,正式环境一定要分开实现,以免影响服务的正常使用和性能. 准备工作: 操作系统:centos7.2 Mongodb版本:3.4.1 ...
- Installing haproxy load balancing for http and https--转载
This example will guide you through a simple IP based load balancing solution that handles ssl traff ...