Mysql(条件查询)

(1)关键字and or  >  <  =  >= <=    between ....and   not between...and

select sname--查询学号为2017151的学生姓名
from Student
where studentno='2017151'

(2)属性 in(A,B,C,……)-->属性 = A or 属性=B or 属性= C……

select sname ,studentno  --选择分数为777,789,799的学生的姓名和学号
from Student 
where point in(777,789,799)

(3)like:只用于文本匹配查询

select sname   --查询姓刘的学生,%为任意个数的字
from Student 
where sname like '刘%'
select sname   --查询刘aa,名字为两个字,_为一个字
from Student 
where sname like '刘__'

如在匹配中遇到_或%,则需要在前面加/转义

(4)条件查询中如果某一属性为空,用 is NULL 

select  studentno,sname,classno--查询email为空的学生信息
from student
where email is null

 (5)聚集函数

COUNT:统计一列中值的个数

SUM:计算一列值的总和

AVG:平均值

MAX:最大值

MIN:最小值

select MIN(point) MIN,MAX(point) 
from student

(6)group by

select MIN(point) MIN,MAX(point) MAX--查询每个班的最低分和最高分
from student
group  by classno

(7)HAVING作用对象为组,跟在GROUP BY 后

select studentno--查询至少选修了三门课程的学生编号
from score
group by studentno
having COUNT(courseno)>=3 
原文地址:https://www.cnblogs.com/zhai1997/p/11373001.html