当前位置: 首页 > news >正文

Mysql数据库 5.SQL语言聚合函数 语言日期-字符串函数

一、聚合函数

SQL中提供了一些可以对查询的记录的列进行计算的函数——聚合函数

1.count() 统计函数,统计满足条件的指定字符的值的个数

统计表中rebirth_mood个数

select count(列名) from 表名;

#统计表中rebirth_name='lcl'的个数

select count(列名) from 表名 where 限制条件;

2.max()函数,统计满足指定条件的字符最大的值 

查询表中rebirth_name最大的一项

select max(列名) from 表名;

查询加入条件判断的最大的一项

select max(列名) from 表名 where 约束条件 ;

 3.min()函数,统计满足指定条件的字符最小的值

 查询表中rebirth_name最小的一项

select min()列名 from 表名 where 约束条件;

4.sum()函数,计算和,查询满足条件的记录中,指定的列的总和

select sum(数据列) from 表名;

 查询表中某一列的总和

select sum(列名) from 表名 ;

查询表中某一列有了约束条件的项的总和

select sum(列名) from 表名 where 约束条件;

5.avg()函数,求平均值,查询满足条件的记录中 计算指定列的平均值

查询某一列中的平均值

select avg(列名) from 表名 ;

 

查询某一列中有了约束条件的项的平均值

select avg(列名) from 表名 where 约束条件 ;

二、日期函数和字符串函数

日期函数 

 时间添加和时间函数

#添加数据在rebir表中better_time的列
insert into rebirth(rebirth_name,rebirth_happen,rebirth_time,rebirth_mood,rebirth_go,better_time
)values('lvcl','变好',20230929,'expected','insist','2023-10-26 21:43:00'
);#时间赋值为当前时间 now()函数
insert into rebirth(rebirth_name,rebirth_happen,rebirth_time,rebirth_mood,rebirth_go,better_time
)values('wp','变好',20230928,'health','health',now()
);#观察新增数据
select * from rebirth;

now()函数得到当前日期

sysdate()函数获取当前日期 系统时间

#时间赋值为当前时间 now()函数
insert into rebirth(rebirth_name,rebirth_happen,rebirth_time,rebirth_mood,rebirth_go,better_time
)values('lxr','变好',20231117,'health','better',sysdate()
);

修改表中数据 update

#修改名字为lxr的数据的happen项为merry
update rebirth set rebirth_happen ='merry' where rebirth_name='lxr';

三、字符串函数

就是通过SQL指令对字符串进行处理

拼接多列 contact函数

select contact(列名1,连接符号,列名2) from 表名;

#将name和go两字段拼接在一起 用中间的内容作拼接
select concat(rebirth_name,'-best-',rebirth_go) from rebirth ; 

uppper(列名)将该列字段的所有值转化为大写

lower(列名)将该字段的所有值转化为小写

upper(列名)将字段的值转为大写

select upper(列名) from 表名;

#upper(列名)将字段的值转为大写
select upper(rebirth_name) from rebirth ;

lower(列名)将该字段所有值转为小写

select  lower(列名) from 表名;

#lower (列名) 将所有字段的值转为小写
select lower(rebirth_name) from rebirth ;

substring函数 字符串拆分函数

substring(列名,截取开始位置,截取位数)

#substring(列名,截取开始位置,截取位数)截取字符串部分
select rebirth_name,substring(rebirth_time,5,4) from rebirth;

http://www.lryc.cn/news/208125.html

相关文章:

  • 使用Linux JumpServer 堡垒机进行远程访问
  • postgresql14管理(五)-tablespace
  • Echarts-3D柱状图
  • vue中组件传值 引用页面与组件页面绑定参数 vue省市地区街道级联选择组件
  • componentDidMount只执行一次的解决方法
  • React之diff原理
  • ElasticSearch中关于Nasted嵌套查询的介绍:生动案例,通俗易懂,彻底吸收
  • 系列二、Spring的优缺点是什么
  • ESP32网络开发实例-HTTP-GET请求
  • PHP:json_encode和json_decode用法
  • Kafka-Java二:Spring配置kafka消息发送端的缓冲区
  • 【ArcGIS模型构建器】05:批量为多个矢量数据添加相同的字段
  • 坤坤的悲伤生活
  • 职业技术认证:《研发效能(DevOps)工程师》——开启职业发展新篇章
  • gin 框架出现runtime error: index out of range [0] with length 0
  • 【高阶数据结构】B树
  • Android-Framework 应用间跳转时,提供 Android Broadcast 通知
  • 【Javascript】函数返回值的作用
  • 蓝桥杯 Java k倍区间
  • 万宾科技亮相2023中国传感器与应用技术大会,创始人CEO发表演讲
  • #力扣:LCP 06. 拿硬币@FDDL
  • 【Node.js】暴露自定义响应头和预检请求的时机
  • 包管理工具与配置文件package.json
  • uni-app:解决异步请求返回值问题
  • <多线程章节七>wait() 和 notify()
  • 竹云产品入选《2023年度上海市网络安全产业创新攻关成果目录》
  • 客户端负载均衡策略:loadBalancer,ribbon
  • canvas基础3 -- 交互
  • Flutter——最详细(Scaffold)使用教程
  • C语言编写图形化界面-创建按钮-为其指定样式