LeetCode--596.超过5名学生的课

    科技2022-07-10  164

    有一个courses表,有:student(学生)和class (课程)。

    请列出所有超过或等于5名学生的课

    -- ---------------------------- -- Table structure for `courses` -- ---------------------------- DROP TABLE IF EXISTS `courses`; CREATE TABLE `courses` ( `student` varchar(255) DEFAULT NULL, `class`varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Records of courses -- ---------------------------- INSERT INTO `courses` VALUES ('A', 'Math'); INSERT INTO `courses` VALUES ('B', 'English'); INSERT INTO `courses` VALUES ('C', 'Math'); INSERT INTO `courses` VALUES ('D', 'Biology'); INSERT INTO `courses` VALUES ('E', 'Math'); INSERT INTO `courses` VALUES ('F', 'Computer'); INSERT INTO `courses` VALUES ('G', 'Math'); INSERT INTO `courses` VALUES ('H', 'Math'); INSERT INTO `courses` VALUES ('I', 'Math'); SELECT class from courses group by class having count(DISTINCT student) >= 5;
    Processed: 0.050, SQL: 8