mysql查询语句

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql查询语句相关的知识,希望对你有一定的参考价值。

select 字段1,字段2 from 表1,表2 where 字段 group by 分组字段 having 字段 order by 字段  ASC|DESC  limit m,n 

一、查询所有

select * from student;
select name as 姓名 from student;
select name 姓名 from student;

二、条件查询

1.查询学生id等于1

selet * from student where student_id;

2.查询name字段为null

selet * from student where name is null;

3.查询name字段不为null

select * from student where name is not null;

4.查询name字段为空字符串

select * from student where name =‘‘;

5.查询name字段不为空字符串且不为null

select * from student where name !=‘‘;

6.查询city字段存在河南省和山东省的数据

select * from where city in(山东省,河南省);

7.查询age在25到30之间

select * from student where age between 25 and 30;

8.查询age不在20到30之间

select * from student where age not between 20 and 30;

9.查询第一个字是郭的数据

select * from student where name like 郭%;

10查询第一个字是郭的两个字得数据

select * from student where name like 郭_;

11查询存在郭的字得数据

select * from student where name like %郭%;

三、分组查询

1.分组性别

select sex,count(*) from student group by sex;

2.分组性别前条件查询

select sex,count(*) from student where name !=李白 group by sex;

3.分组性别后条件查询

select sex,count(*) from student group by sex having count(*)>5;

4.查询后分组然后再条件查询

select sex,count(*) from student where name !=李白 group by sex having count(*)>5;

四、排序查询

 1.降序排序

select * from student order by salary desc;

2.降序后再升序排序

 select * from student order by salary desc,bonus asc;

五、聚合函数

count(*)
sum(salary)
avg(salary)
min(salary)
max(salary)

 

以上是关于mysql查询语句的主要内容,如果未能解决你的问题,请参考以下文章

sql语句 嵌套查询 排序

sql mysql查询/ db片段

[AndroidStudio]_[初级]_[配置自动完成的代码片段]

[AndroidStudio]_[初级]_[配置自动完成的代码片段]

在mysql语句中查询第四条到第十条记录代码怎么写?

sql嵌套删除语句