我爱编程

MySQL数据库查询

2018-04-11  本文已影响0人  诗人丶

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;
上一篇下一篇

猜你喜欢

热点阅读