数据库的基本查询

博主最近在学习数据库,今天给大家分享下数据库的一些基本查询语法,就拿班级学生人数成绩来举例子吧
1 根据Class_id对班级女生进行降序排序
//*代表所有列
select * from student where gender = ‘女’
order by class_id desc;

insert into score values(6,3,1,50);

select * from score;
//根据course_id升序,,number desc降序查询score表的所有信息
select * from score order by course_id ,number desc;
//查询student中女生的数量
select count(*) from student where gender = ‘女’;
//查询最高法
select max(number) from score;
//查询最高分的人的 student_id,course_id ;
select student_id,course_id from score where number = (select max(number) from score);
//查询一行一列
select * from score order by number desc limit 0,1;
查询某一列的平均数据
select course_id ‘学科号’, avg(number) as ‘平均成绩’ from score group by course_id;

select avg(number) as ‘平均成绩’ from score;
//查询某一列中大于70小于90的数据
select student_id from score where number >70 and number<90;
查询所有学生的Sname,Cno,Degree列
select Sname,Cno,Degree from Score,student where Score.Sno=student.sno;
查询以某个数或者其他开头的
select*from score where Cno like ‘3%’;

你可能感兴趣的:(数据库的基本查询)