查询每个班级的数学总分
select class, sum(math) from student group by class;
查询每个班级数学总分大于100分的班级和总分数
select class,sum(math)from student group by class having sum(math)>100;
聚合函数查询出来的字段取别名后面的条件就可以使用别名
select class,sum(math)as s from student group by class having s>100;
select * from student; 查询student表所有字段数据
select name from student查询student表所有的name
select name,math from student;查询name和 math两个字段
select * from student where calss=1833;where后加条件,满足某个条件的数据 ,查询班级为1833班的所有消息
select * from student where class=1833 and class=1834;错误
select * from student where class=1833 or class=1834 正解
select * from student where calss=1833 and name="zhangsan";查询1833和姓名为zhangsan的信息
select * from student where class !=1833 查询班级不为1833班的信息
select * from student where class <> 1833也是表示 查询班级不为1833 的信息
select * from student where age between 22 and 27;查询年纪22-27的学生信息
select * from student where age>=22 and age<=27;查询年纪22-27的学生信息
select * from student where class is null;查询班级为空的学生信息
select * from student where name like ‘%ao%' 查询学生姓名中间包含
ao的学生信息
select * from student where id limit 3,5;查询4-8行数据
select * from student where id limit 8取前八行数据
select * from student order by age asc;按照年纪升序排列
select * from student order by age desc;按照年纪降序
select count(class) from student;统计班级个数
select count(*) from student统计所有字段,共有多少行
select sum(math) from student;查询表中数学成绩总和
select avg(math) from student查询平均数学成绩
select max(math) from student 查询最大数学成绩
|