{"id":7955,"date":"2024-03-29T12:51:22","date_gmt":"2024-03-29T04:51:22","guid":{"rendered":"https:\/\/white-night.club\/?p=7955"},"modified":"2024-03-29T14:16:35","modified_gmt":"2024-03-29T06:16:35","slug":"ad168","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2024\/03\/29\/ad168\/","title":{"rendered":"178. \u5206\u6570\u6392\u540d"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/rank-scores\/description\/\">https:\/\/leetcode.cn\/problems\/rank-scores\/description\/<\/a><\/p>\n\n\n\n<p>dense_rank\u79d2\u4e86\u3002\u8fde\u6d3e\u751f\u8868\u90fd\u4e0d\u7528\u3002<\/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 score,dense_rank()over(ORDER BY score DESC) AS 'rank'\nFROM Scores\" 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<\/span><span style=\"color: #D4D4D4\"> score,<\/span><span style=\"color: #DCDCAA\">dense_rank<\/span><span style=\"color: #D4D4D4\">()<\/span><span style=\"color: #569CD6\">over<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">ORDER BY<\/span><span style=\"color: #D4D4D4\"> score <\/span><span style=\"color: #569CD6\">DESC<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;rank&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Scores<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4e0d\u8fc7\u770b\u4e86\u770b\u9898\u89e3\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u7528\u5f00\u7a97\u3002\u4e0d\u8fc7\u8bf4\u5b9e\u8bdd\u521a\u5f00\u59cb\u770b\u8fd9\u4e2a\u89e3\u6cd5\uff0cS1.score\u548crank\u662f\u600e\u4e48\u62fc\u63a5\u5728\u4e00\u8d77\u7684\uff0c\u6ca1\u600e\u4e48\u770b\u61c2\u3002<\/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 S1.score,(\n    SELECT COUNT(DISTINCT S2.score)\n    FROM Scores AS S2\n    WHERE S1.score\u2264S2.score\n) AS 'rank'\nFROM Scores AS S1\nORDER BY S1.score DESC\" 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<\/span><span style=\"color: #D4D4D4\"> S1.score,(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">COUNT<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">DISTINCT<\/span><span style=\"color: #D4D4D4\"> S2.score)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Scores <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> S2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> S1.score\u2264S2.score<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;rank&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Scores <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> S1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ORDER BY<\/span><span style=\"color: #D4D4D4\"> S1.score <\/span><span style=\"color: #569CD6\">DESC<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u540e\u9762\u60f3\u4e86\u4e0b\uff0c\u662f\u5148\u9009S1.score\uff0c\u6bd4\u59824.0\uff0c\u90a3\u5c31\u662fS1.score=4.0\u3002\u7136\u540e\u5728score\u65c1\u8fb9\u65b0\u589e\u4e00\u5217rank\u3002\u6839\u636e\u8fd9\u4e2a4.0\u53bb\u627e\u6bd44.0\u5927\u7684\u5206\u6570\u3002\u5f53\u6210\u8fed\u4ee3\u53bb\u770b\u5c31\u660e\u767d\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>score<\/td><td>rank<\/td><\/tr><tr><td>4.0<\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>dense_rank+COUNT()<\/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\/7955"}],"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=7955"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/7955\/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=7955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=7955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=7955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}