模糊查询
select *
from 表
where 列
like '开头%' 或 '%结尾';
内连接
方法一
select 需要显示的列
from A表 , B表 , C表 ···
where A表的列 = B表的列 and B表的列 = C表的列 and ··· and 条件;
方法二
select 需要显示的列
from A表
inner join B表 on A表的列 = B表的列
inner join C表 on B表的列 = C表的列 and 条件
where 条件;
去重
distinct
select distinct 需要显示的列
from 表
where 条件;
分组
group by
select *
from 表
where 条件
group by 列 ;
排序
oder by
-- 从小到大 asc 可以省略不写
select *
from 表
order by 要排序的列 asc;
-- 从大到小
select *
from 表
order by 要排序的列 desc;
常用函数
count() 计数
sum() 求和
avg() 求平均值
max() 求最大值
min() 求最小值
select 需要显示的列 , count(*)
from 表,表,表···
where 条件;
分页
limit
函数有两个参数,第一个是起点,第二个是一些显示的条数
select *
from 表
limit (显示从第几个开始x+1)x , (显示几个数据y) y;