单行处理函数
lower 转换小写
upper 转换大写
select upper(name) as name from stu;
substr 取子串(substr(截取的字符串,起始下标,截取的长度)
select substr(name,1,2) as name from stu;
找出名字的第一个字母是z的信息?
1.模糊查询:
select name from stu where name like 'z%';
2.substr函数:
select name from stu where substr(name,1,1) = 'z';
转成大写:select upper(substr(name,1,2)) as name from stu;
length 取长度
select length(name) as namelength from stu;
trim 去空格(where name = trim(' lisi'))
concat 函数进行字符串的拼接
str_t_data 将字符串转换成日期
round 四舍五入(round(1234.567,1)1表示保留一个小数,0表示保留到个位,-1表示保留的十位)
rand() 生成随机数
ifnull 可以将Null转换一个具体值
data_format 格式化日期
format 设置千分位
case..when..then..when..then..else..end
分组函数(多行处理函数)
输出多行,最终一行
count 计数
sum 求和
avg 平均值
max 最大值
min 最小值
注意事项:
分组函数在使用前必须先分组,然后才能用,如果没有分组,整张表默认为一组
1.分组函数自动忽略null
2.count(具体字段):表示统计该字段下不为null的元素的总数。
count(*):统计当中的总行数,一行数据中有一列不为null,这行数据就是有效的。
3.分组函数不能直接使用在where子句中。
4.所有分组函数可以组合一起用
分组查询
先分组,再操作
select
...
from
...
where
...
group by
...
order by
...
执行顺序:from-- where-- group by-- select-- order by
把查询结果去重
select distinct id,name,gender from stu;
内连接之等值连接
select
e.ename,d.dname
from
emp e
join
dept d
on
e.deptno = d.deptnp
where
筛选条件