近日去某家公司面试开发岗位,遇到该Sql题目,特地分享出来给大家,希望对你们有帮助
Mysql高级查询 ~~ >=80表示优秀,>=60且<80表示几个,<60表示不及格有一张表,里面有3个字段:语文,数学,英语。
其中有3条记录分别表示语文70分,数学80分,英语58分,
请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。
显示格式:
语文 数学 英语
及格 优秀 不及格
------------------------------------------
条件:
CREATE TABLE A (语文 int, 数学 int, 英语 int); insert into A values(70,80,58); insert into A values(100,50,60); select * from A;答案:
select (case when 语文 >=80 then ‘优秀’ when 语文 >=60 then ‘及格’else ‘不及格’end) 语文, (casewhen 数学 >=80then‘优秀’ when 数学 >=60 then‘及格’ else ‘不及格’end) 数学, (casewhen 英语 >=80then ‘优秀’ when 英语 >=60 then ‘及格’else ‘不及格’end) 英语 from A;