CREATE TABLE `t_demo` ( `id` int(32) NOT NULL, `name` varchar(255) DEFAULT NULL, `age` int(2) DEFAULT NULL, `num` int(3) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `t_demo` VALUES ('1', '张三', '21', '69'); INSERT INTO `t_demo` VALUES ('2', '李四', '22', '98'); INSERT INTO `t_demo` VALUES ('3', '王五', '20', '54'); INSERT INTO `t_demo` VALUES ('4', '赵甜', '22', '80');
SELECT *, CASE WHEN t.num >= 85 THEN '优秀' WHEN t.num < 90 AND t.num>= 60 THEN '一般' ELSE '不及格' END AS level FROM t_demo t;
查询结构: