leetcode 182. Duplicate Emails having的用法 SQL执行顺序

时间:2021-03-17 04:38:23

https://leetcode.com/problems/duplicate-emails/description/

首先sql的执行顺序是

from-->where-->group by--->having-->select-->order by

所以用了group后,用where判断是错误的

# Write your MySQL query statement below
select distinct Email //这里不需要distinct,因为group后,相同的只算一个
from Person
group by Person.Email
having count(Email) >= 2;

https://leetcode.com/problems/classes-more-than-5-students/description/

group by之后,所有你group了的东西会放在一起。只算一个

不会输出多次

# Write your MySQL query statement below
select class
from courses
group by class
having count(DISTINCT student) >= 5;