数据库查询select
select 字段名 from 表名 where 条件;
表示查询所有字段
条件:in(具体的值,而不是区间)
通配符 %任意多个字符 _任意一个字符。
排序 order by 字段 ; 默认升序 sec升序 desc降序 多个字段进行排序时越靠前的主导作用越大,当前者无法进行排序时才启用后者
from》where》select》order by
计数count()总记录数 count(具体字段)字段中不为空的元素总数
求和 sun(字段)
平均数 avg(字段)
最大最小值 max() min()
按字段分组 group by 字段;
对分组后的数据进行过滤 having
select。。from。。where。。group by。。having。。order by。。
5 1 2 3 4 6
where后面不可以直接使用分组函数
去除重复记录 distinct eg:slect distinct job from emp;
正则表达式 regexp
字段名 regexp ’匹配方式[ ]‘ [a,b,c] 包含中括号中的任意一个都会被查处出来。 正则表达式中点. 表示一个字符
匹配任意字符 [a*b]可为0 吧 b前有无a均可 [a+b]b前面必有a
以^开始 ,以$结束。
limit是mysql当中特有的,其他数据库没有,不通用
limit取结果集当中的部分数据
语法:limit startIndex,length
startIndex:表示起始位置,从0开始,0表示第一条数据
length:表示取几个
(1)取出工资前5名的员工
select ename,sal from emp order by sal desc;
select ename,sal from emp order by sal desc limit 0,5;
select ename,sal from emp order by sal desc limit 5;//只写一个数默认起始位置就是0