美文网首页Ways to be a Data Scientist
180605_Conditional SELECT with C

180605_Conditional SELECT with C

作者: 郑磊_4135 | 来源:发表于2018-06-05 10:04 被阅读0次

    There is a table courses with columns: student and class

    Please list out all classes which have more than or equal to 5 students.

    For example, the table:

    student class
    A Math
    B English
    C Math
    D Biology
    E Math
    F Computer
    G Math
    H Math
    I Math

    Should output:

    class
    Math

    Note:
    The students should not be counted duplicate in each course.

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

    相关文章

      网友评论

        本文标题:180605_Conditional SELECT with C

        本文链接:https://www.haomeiwen.com/subject/unqpsftx.html