1.比较运算符:<,>,=,<=,>=
selsect * from 表 where num > 30 and grade < 90;
2.逻辑运算符:not,and,or
selsect * from 表 where not num = 30 and grade < 90;
注意:not只对单边起作用。
3.模糊查询:like
selsect * from 表 where 字段 like '%内容%';
4.范围查询:between...and,in
selsect * from 表 where num between 30 and 100;
5.判断空:null
selsect * from 表 where num is not null;
注意:只有null是空,其余可能为换行符/空格/制表符(tab)。
2.排序:selsect * from 表 order by num desc, grade asc;
3.聚合函数:selsect count(*) from 表;
count():
max():
min():
sum():
avg():
注意:where后不可以接聚合函数。
4.分组:group by
selsect sort,count(*) from 表 group by sort;
注意:分组多和聚合函数配合使用。
having
selsect sort,count(*) from 表 group by sort having avg(age) > 20;
注意:having后可以接聚合函数。
5.分页查询:selsect * from 表 where limit 0,5;
查询前五条0代表起始行号,5需要代表查询几行信息。
limit:分页
start:起始行号
count:数据行数
每页查询m条数据,求显示第n页的数据。
公式:limit(n-1)*m,m
排序+limit搭配
selsect * from 表 order by num limit 0,5;
c3159d409a8b 8 月前
14ec10d66858 8 月前