MySql学习day02:DQL语句:Select

创建student表,内容如下:

select * from student;

在所有学生数学分数上加10分特长分。

select name,english+10 as english from student;

统计每个学生的总分。

select (chinese+english+math) as '总分' from student;

使用别名表示学生分数

select name as '姓名',chinese,english,math from student;

统计平均分

select name,(chinese+english+math)/3 from student;

查询姓名为ww的学生成绩

select * from student where name='ww';

查询英语成绩大于75的同学

select * from student where english>=75;

查询总分大于220的同学

select * from student where (chinese+english+math)>=220;

查询英语分数在 70-75之间的同学。

select * from student where english BETWEEN 70 and 75;

select * from student where english>=70 and english<=75;

查询数学分数为83,84,85的同学。

select * from student where math in(83,84,85);

查询所有姓李的学生成绩。

select * from student where name like 'li%';

查询数学分>82并且语文分>64的同学。

 select * from student where math>82 and chinese>64;

对数学成绩排序后输出(如果不写排序规则,则默认按升序排序)
asc:升序,desc:降序

select * from student order by math;

select * from student order by math asc;

select * from student order by math desc;

指定多个字段进行排序:先按第一个字段排序,如果相同则按第二个字段排序

select * from student order by math asc , chinese desc;

对总分排序后输出,再按从高到低的顺序输出。

select name as 姓名,(chinese+english+math) as 总分 from student order by 总分 desc;

对姓l的学生成绩排序输出

select *,(chinese+english+math) as total from student where name like 'l%' order by total desc;

显示student表格中的前三行

select * from student limit 3;

显示表格中的3-5行(第一个值表示偏移的行数,第二个表示显示的总行数)

select * from student limit 2,3

猜你喜欢

转载自blog.csdn.net/weixin_43800846/article/details/89158380