码迷,mamicode.com
首页 > 数据库 > 详细

mysql查询语句

时间:2018-03-12 18:46:44      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:font   span   city   sele   where   山东省   聚合函数   student   mysq   

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查询语句

标签:font   span   city   sele   where   山东省   聚合函数   student   mysq   

原文地址:https://www.cnblogs.com/mengor/p/8550475.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!