湖南手机版建站系统开发,网站建设策划报价单,用vs2017做网站,大学生招聘就业网一、聚合函数
SQL中提供了一些可以对查询的记录的列进行计算的函数——聚合函数 1.count#xff08;#xff09; 统计函数#xff0c;统计满足条件的指定字符的值的个数 统计表中rebirth_mood个数
select count(列名) from 表名; #统计表中rebirth_namelcl的个数
select …一、聚合函数
SQL中提供了一些可以对查询的记录的列进行计算的函数——聚合函数 1.count 统计函数统计满足条件的指定字符的值的个数 统计表中rebirth_mood个数
select count(列名) from 表名; #统计表中rebirth_namelcl的个数
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_namelxr; 三、字符串函数
就是通过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;