{"id":7977,"date":"2024-04-01T10:15:56","date_gmt":"2024-04-01T02:15:56","guid":{"rendered":"https:\/\/white-night.club\/?p=7977"},"modified":"2024-04-01T10:15:56","modified_gmt":"2024-04-01T02:15:56","slug":"ad171","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2024\/04\/01\/ad171\/","title":{"rendered":"180. \u8fde\u7eed\u51fa\u73b0\u7684\u6570\u5b57"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/consecutive-numbers\/description\/\">https:\/\/leetcode.cn\/problems\/consecutive-numbers\/description\/<\/a><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">SQL<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# Write your MySQL query statement below\nSELECT DISTINCT A.num AS ConsecutiveNums\nFROM Logs AS A\nJOIN Logs AS B \nON B.id-A.id=1 AND A.num=B.num\nJOIN Logs AS C\nON C.id-B.id=1 AND B.num=C.num;\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\"># Write your MySQL query <\/span><span style=\"color: #569CD6\">statement<\/span><span style=\"color: #D4D4D4\"> below<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT DISTINCT<\/span><span style=\"color: #D4D4D4\"> A.num <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> ConsecutiveNums<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Logs <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> A<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">JOIN<\/span><span style=\"color: #D4D4D4\"> Logs <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> B <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ON<\/span><span style=\"color: #D4D4D4\"> B.id-A.id=<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">AND<\/span><span style=\"color: #D4D4D4\"> A.num=B.num<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">JOIN<\/span><span style=\"color: #D4D4D4\"> Logs <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> C<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ON<\/span><span style=\"color: #D4D4D4\"> C.id-B.id=<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">AND<\/span><span style=\"color: #D4D4D4\"> B.num=C.num;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u5982\u679c\u7528LEFT JOIN,\u5f53\u51fa\u73b0\u201c1 1 2\u201d\u8fd9\u79cd\u60c5\u51b5\u7684\u65f6\u5019\uff0c\u7531\u4e8eLEFT JOIN\u5339\u914d\u5230\u4e0d\u5b58\u5728\u7684\u8bb0\u5f55\u65f6\u4f1a\u8fd4\u56deNULL\u800c\u4e0d\u662f\u7a7a\uff0c\u6240\u4ee5\u7ecf\u8fc7\u4e24\u6b21LEFT JOIN\u4e4b\u540e\u5f97\u5230\u7684\u7ed3\u679c\u4e3a\u201d1 1 NULL\u201c\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u5f97\u7528INNER JOIN\uff0c\u4e5f\u5c31\u662fJOIN\u3002\u90a3\u4e48\u201d1 1 2\u201c\u8fd9\u79cd\u5728\u4e24\u6b21JOIN\u4e4b\u540e\u5f97\u5230\u7684\u7ed3\u679c\u96c6\u4e3a\u201d1 1\u201c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LEFT JOIN\u4e0eINNER JOIN<\/p>\n","protected":false},"author":1,"featured_media":7932,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/7977"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=7977"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/7977\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/7932"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=7977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=7977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=7977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}