MySQL数据库查询

1、(查询)条件

查询基本语法

select * from 表名;

消除重复行

select distinct 字段名 from 表名;

where 使用where条件对数据进行筛选

select * from 表名 where 条件;

逻辑运算符

not
and
or

模糊查询

select * from  where 字段名 in(条件1,2,3);

优先级

小括号>not>逻辑运算符

2、(查询)聚合

查询总数

select count(*) from 表名;

平均值

select avg(*) from 表名;

求和

select sum(*) from 表名;

最大值

select max(*) from 表名;

最小值

select min(*) from 表名;

3、(查询)分组

语法

select 列1,列2,聚合...from 表名 group by 列1,列2,列3;

4、(查询)排序

语法

select * from 表名
order by 列1 asc|desc,列2 asc|desc,...;

5、(查询)分页

语法

select * from 表名
limit start,count;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容