Classes More Than 5 Students


  • 0

    Click here to see the full article post


  • 0

    Looks like this piece of code

    SELECT
    Employee.name, Bonus.bonus
    FROM
    Employee
    LEFT JOIN
    Bonus ON Employee.empid = Bonus.empid
    WHERE
    bonus < 1000 OR bonus IS NULL
    ;

    should not be in this post.
    Right?


  • 0

    Right. It has been removed. And thanks for the feedback.


  • 0
    G

    SELECT
    class
    FROM
    courses
    GROUP BY class
    HAVING COUNT(student) >= 5
    ;

    what is the difference with or without distinct, I think any one even the same name can be counted, and it's not a major problem.


  • 0
    N

    @glad2be, The Note at the very bottom states: "Note: The students should not be counted duplicate in each course." Thus you need the distinct.


  • 0
    C

    select courses.class as class
    from courses
    group by courses.class
    having count(class)>=5;

    sorry Why can't I ues this way to soluve this problem?


  • 0
    W

    select class
    from
    (select class, count(*) as num
    from courses
    group by class
    ) as a
    where num >= 5;

    why it's wrong answer?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.