{"id":2410,"date":"2018-04-02T22:55:48","date_gmt":"2018-04-03T05:55:48","guid":{"rendered":"http:\/\/zxi.mytechroad.com\/blog\/?p=2410"},"modified":"2018-04-02T22:55:58","modified_gmt":"2018-04-03T05:55:58","slug":"leetcode-596-classes-more-than-5-students","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/sql\/leetcode-596-classes-more-than-5-students\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 596. Classes More Than 5 Students"},"content":{"rendered":"<h1><strong>Problem<\/strong><\/h1>\n<p>There is a table\u00a0<code>courses<\/code>\u00a0with columns:\u00a0<b>student<\/b>\u00a0and\u00a0<b>class<\/b><\/p>\n<p>Please list out all classes which have more than or equal to 5 students.<\/p>\n<p>For example, the table:<\/p>\n<pre class=\"crayon:false\">+---------+------------+\r\n| student | class      |\r\n+---------+------------+\r\n| A       | Math       |\r\n| B       | English    |\r\n| C       | Math       |\r\n| D       | Biology    |\r\n| E       | Math       |\r\n| F       | Computer   |\r\n| G       | Math       |\r\n| H       | Math       |\r\n| I       | Math       |\r\n+---------+------------+\r\n<\/pre>\n<p>Should output:<\/p>\n<pre class=\"crayon:false \">+---------+\r\n| class   |\r\n+---------+\r\n| Math    |\r\n+---------+\r\n<\/pre>\n<p><b>Note:<\/b><br \/>\nThe students should not be counted duplicate in each course.<\/p>\n<h1><strong>Solution<\/strong><\/h1>\n<p>SQL<\/p>\n<pre class=\"lang:default decode:true \"># Author: Huahua\r\n# Running time: 1756 ms\r\nselect class from courses group by class having count(distinct student) &gt;= 5<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem There is a table\u00a0courses\u00a0with columns:\u00a0student\u00a0and\u00a0class Please list out all classes which have more than or equal to 5 students. For example, the table: +&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;+&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[238],"tags":[288,289,287],"class_list":["post-2410","post","type-post","status-publish","format-standard","hentry","category-sql","tag-count","tag-distinct","tag-having","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/2410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=2410"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/2410\/revisions"}],"predecessor-version":[{"id":2412,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/2410\/revisions\/2412"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=2410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=2410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=2410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}