トピックへのリンク:https://leetcode-cn.com/problems/classes-more-than-5-students/
タイトル
あるcourses
学生(学生)とクラス(コース):テーブルがあるが。
よりやクラスで5人の学生に等しいすべて記入してください。
たとえば、テーブル:
+ --------- + ------------ +
|学生|クラス|
+ --------- + ---------- - +
| A |数学|
| B |辞書英語|
| C |数学|
| D |生物|
| E |数学|
| F. |コンピュータ|
| G |数学|
| H |数学|
| I |数学|
+ - -------- + ------------ +
出力すべきです:
+ --------- +
| クラス|
+ --------- +
| 数学|
+ --------- +
注:
学生は各レッスンで二度数えられるべきではありません。
出典:ボタン(LeetCode)滞在
:リンクhttps://leetcode-cn.com/problems/classes-more-than-5-students
すべてのネットワークからの控除が著作権を保有します。商業転載は許可公式、非商用の転載は、ソースを明記してくださいお問い合わせください。
答え
直接解
---- oracle ----
/* Write your PL/SQL query statement below */
select b.class
from
(
select class,
count(distinct student) as cnt
from courses
group by class
) b
where cnt >= 5; ---- 469ms
使用having
簡略化された単語を。
---- oracle ----
select class
from courses
group by class
having count(distinct student) >= 5; ---- 466ms
考えます
この問題は少し楽に、エントリーレベル、それを直接このような。