SQL语句

模糊查询

select * 
fromwherelike '开头%''%结尾';

内连接

方法一

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 需要显示的列
fromwhere 条件;

分组

group by

select *
fromwhere 条件 
group by;

排序

oder by

-- 从小到大 asc 可以省略不写
select *
fromorder by 要排序的列 asc;
-- 从大到小
select *
fromorder by 要排序的列 desc;

常用函数

count() 计数
sum() 求和
avg() 求平均值
max() 求最大值
min() 求最小值
select 需要显示的列 , count(*)
from,,表···
where 条件;

分页

limit 函数有两个参数,第一个是起点,第二个是一些显示的条数

select *
fromlimit (显示从第几个开始x+1)x , (显示几个数据y) y;

版权声明:本文为LLcwh原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。