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

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;

 

posted on 2017-11-24 14:29  stupid_one  阅读(129)  评论(0编辑  收藏  举报

导航