You are here
Home > Mysql

Mysql 随机数 if case

CREATE TABLE `stu` (
  `Sid` varchar(6) DEFAULT NULL,
  `Sname` varchar(10) DEFAULT NULL,
  `Sage` datetime DEFAULT NULL,
  `Ssex` varchar(10) DEFAULT NULL,
  `level` enum('A','B','C') DEFAULT NULL,
  `score` tinyint(4) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
INSERT INTO `stu` VALUES ('01','赵雷','1990-05-20 21:30:45','男',null,null),
('02','钱电','1995-08-02 11:00:05','男',null,null),
('03','孙风','1993-04-10 00:30:40','男',null,null),
('04','李云','1991-01-31 11:00:35','男',null,null),
('05','周梅','1996-11-10 20:20:33','女',null,null),
('06','吴兰','1993-05-06 00:25:45','女',null,null),
('07','郑竹','1998-05-05 18:34:56','女',null,null),
('08','王菊','1991-05-20 15:18:09','女',null,null);

update stu set score =FLOOR(30 + RAND() * (100 - 1 + 1));
update stu set level = if(
    score>=90,'A',if(score<60,'C','B')
);
Top