有一個courses
表 ,有: student (學生) 和 class (課程)。sql
請列出全部超過或等於5名學生的課。spa
例如,表:code
+---------+------------+ | student | class | +---------+------------+ | A | Math | | B | English | | C | Math | | D | Biology | | E | Math | | F | Computer | | G | Math | | H | Math | | I | Math | +---------+------------+
應該輸出:io
+---------+ | class | +---------+ | Math | +---------+
Note:
學生在每一個課中不該被重複計算。class
答案:select
select tmp.class from ( select DISTINCT student,class from courses )tmp GROUP BY tmp.class HAVING COUNT(tmp.class) >= 5
一開始沒看到「學生在每一個課中不該被重複計算。」這句話 ,很難受...co