select语句 过滤重复语句(distinct) 举例:
查询学生的总分
select name, math + English + China as '总分' from students;
在姓赵的学生总分基础上, 增加60%,
select name, round((math + English + China) * 1.6, 2) as '新的总分' where name like '赵%';
注意round函数的使用, 能够使结果保留两位小数
where语句
查询英语成绩大于90的学生的成绩
select * from students where English > 90;
查询总分大于200的学生的成绩
select id, name, (math + English + China) as '总分' from students where (math + English + China) > 200;
查询姓名为赵,但是id<90的学生
select * from students where name like '赵%' and id < 90;
查询英语成绩大于语文成绩的学生
select * from students where English > China;
查询总分大于200,并且数学成绩小于语文成绩的姓宋的学生
select * from students where (math + English + China) > 200 and math > China and name like '宋%';
查询英语成绩在80-90 之间的学生
select * from students where English between 80 and 90;
等价于
select * from students where English >=80 and English <= 90;
查询数学成绩为89, 90, 91的学生
select * from students where math = 90 or math = 89 or math =91;
select * from students where math in (89, 90, 91); (推荐)
order by语句 举例:
按照数学成绩 升序排序
select * from students order by math;
按照数学成绩 降序排序
select * from students order by math desc;
按照学生总分降序排列 注意order by 后面 跟的字段 或者是别名, 不能带 '';
select id, name, (English + math + China) as 'totalscore' from students order by totalscore;
对姓李的学生总成绩进行排序
select id, name, (English + math + China) as 'totalscore' from students where name like '李%' order by totalscore;