面试题-2017/6/19
来源:互联网 发布:电脑截动图用什么软件 编辑:程序博客网 时间:2024/06/12 01:51
这是今天遇到的面试题,当时没做出来,回来查了一下开发文档,感觉不是很难
SQL语句:SELECT courseid, coursename,score,IF(60<=score,'pass','nopass') as mark from course ;
在我本机亲测:
原表
查询的到的表:
我突然想加一个需求,例如分数大于90但是小于等于100,mark显示为优;分数大于80但是小于90,mark显示为良;分数大于70但是小于80,mark显示为中;
分数大于60但是小于70,mark显示为及格;小于60显示不及格。现在SQL语句怎么写?
SELECT courseid, coursename,score,
case when score<60 then '不及格'
when (60<=score and score<70) then '及格'
when (70<=score and score<80) then '中'
when (80<=score and score<90) then '良'
else '优' END
as level from course;
原表:
查询得到的表:
参考:
as==alias 别名 (给列添加别名或者给表添加别名)
https://dev.mysql.com/doc/refman/5.7/en/problems-with-alias.html ------(别名的使用)
https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case ------(SQL控制流程功能)
2017-6-19
- 面试题-2017/6/19
- 面试题 19
- 面试题19
- iOS面试题2017
- 2017Android面试题
- 2017面试题
- 2017面试题收集
- 2017面试题收集
- 2017面试题收集
- 2017面试题收集
- 2017面试题收集
- 2017面试题收集
- 2017面试题收集
- iOS面试题2017
- 2017php面试题
- 百度面试题2017
- 2017年面试题
- 2017前端面试题
- android monkey测试
- URAL
- Rotation Matrix To Euler Angles
- poj 2386(深搜或广搜)
- 四元数(Quaternion)和旋转
- 面试题-2017/6/19
- CG在vs中配置方法
- 实现一个简单计算器,表达式为字符串表示
- 点击li弹出对应的index
- Spring MVC工作流程详解
- mybatis学习之添加新用户例子
- URAL
- 初识Python
- android事件分发