{"id":7948,"date":"2024-03-28T17:55:33","date_gmt":"2024-03-28T09:55:33","guid":{"rendered":"https:\/\/white-night.club\/?p=7948"},"modified":"2024-03-29T14:16:00","modified_gmt":"2024-03-29T06:16:00","slug":"ad167","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2024\/03\/28\/ad167\/","title":{"rendered":"176. \u7b2c\u4e8c\u9ad8\u7684\u85aa\u6c34"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/second-highest-salary\/\">https:\/\/leetcode.cn\/problems\/second-highest-salary\/<\/a><\/p>\n\n\n\n<p>\u5178\u4e2d\u5178dense_rank\u3002dense\u7ffb\u8bd1\u6210\u4e2d\u6587\u5c31\u662f\u201c\u5bc6\u96c6\u7684\u201d\uff0c\u6240\u4ee5\u7528dense_rank\u6392\u5e8f\u540erank\u662f1\u30012\u30013\u3001&#8230;\u8fd9\u6837\u5bc6\u96c6\u6392\u5e03\u7684\u3002<\/p>\n\n\n\n<p>IFNULL\u53c8\u5fd8\u4e86\u8981\u52a0\u805a\u5408\u51fd\u6570\uff0c\u56e0\u4e3a\u662f\u6d3e\u751f\u8868\u67e5\u8be2\uff0c\u5982\u679c\u6d3e\u751f\u8868\u4e2d\u627e\u4e0d\u5230rk=2\u7684\u8bb0\u5f55\uff0c\u90a3\u4e48salary\u4e3a\u7a7a\u800c\u4e0d\u662fnull\uff0c\u800cIFNULL\u53ea\u80fd\u5224\u65ad\u201c\u4e3anull\u201d\u800c\u4e0d\u80fd\u5224\u65ad\u201c\u4e3a\u7a7a\u201d\uff0c\u6240\u4ee5\u5f97\u52a0\u4e2a\u805a\u5408\u51fd\u6570\u4f7fsalary\u7684\u8bb0\u5f55\u4e3anull\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 IFNULL(MAX(salary),null) AS SecondHighestSalary\nFROM (\n    SELECT salary,dense_rank()over(order by salary DESC) as rk\n    FROM Employee \n) AS A WHERE rk=2;\" 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\"> <\/span><span style=\"color: #569CD6\">IFNULL<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">MAX<\/span><span style=\"color: #D4D4D4\">(salary),<\/span><span style=\"color: #569CD6\">null<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> SecondHighestSalary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> salary,<\/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\"> salary <\/span><span style=\"color: #569CD6\">DESC<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">as<\/span><span style=\"color: #D4D4D4\"> rk<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Employee <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> A <\/span><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> rk=<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>IFNULL+dense_rank+\u6d3e\u751f\u8868\u67e5\u8be2<\/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\/7948"}],"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=7948"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/7948\/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=7948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=7948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=7948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}