{"id":8086,"date":"2024-04-08T10:03:40","date_gmt":"2024-04-08T02:03:40","guid":{"rendered":"https:\/\/white-night.club\/?p=8086"},"modified":"2024-04-08T10:03:40","modified_gmt":"2024-04-08T02:03:40","slug":"ad177","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2024\/04\/08\/ad177\/","title":{"rendered":"1875. \u5c06\u5de5\u8d44\u76f8\u540c\u7684\u96c7\u5458\u5206\u7ec4"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/group-employees-of-the-same-salary\/description\/\">https:\/\/leetcode.cn\/problems\/group-employees-of-the-same-salary\/description\/<\/a><\/p>\n\n\n\n<p>\u4e00\u5f00\u59cb\u60f3\u7684\u662f\u7528EXISTS\u505a\uff0c\u53ea\u8981\u5de5\u8d44\u7684\u503c\u5728\u8868\u4e2d\u51fa\u73b0\u8d85\u8fc7\u4e00\u6b21\uff0c\u90a3\u4e48\u5b83\u5c31\u53ef\u4ee5\u88ab\u5206\u7ec4\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(2 * 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 A.employee_id,A.name,A.salary,\ndense_rank()over(ORDER BY A.salary ASC) AS team_id\nFROM Employees AS A\nWHERE EXISTS(\n    SELECT salary\n    FROM Employees\n    GROUP BY salary \n    HAVING COUNT(salary)&gt;1 AND A.salary=salary\n)\nORDER BY team_id ASC,employee_id ASC;\" 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\"> A.employee_id,A.name,A.salary,<\/span><\/span>\n<span class=\"line\"><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\"> A.salary <\/span><span style=\"color: #569CD6\">ASC<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> team_id<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Employees <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> A<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">EXISTS<\/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>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Employees<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">GROUP BY<\/span><span style=\"color: #D4D4D4\"> salary <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">HAVING<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">COUNT<\/span><span style=\"color: #D4D4D4\">(salary)&gt;<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">AND<\/span><span style=\"color: #D4D4D4\"> A.salary=salary<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ORDER BY<\/span><span style=\"color: #D4D4D4\"> team_id <\/span><span style=\"color: #569CD6\">ASC<\/span><span style=\"color: #D4D4D4\">,employee_id <\/span><span style=\"color: #569CD6\">ASC<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4f46\u53d1\u73b0\u8fd9\u79cd\u65b9\u6cd5\u8017\u65f6\u6781\u957f\uff0c\u611f\u89c9\u53ef\u4ee5\u518d\u4f18\u5316\u4f18\u5316\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"585\" height=\"447\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/04\/image-2.png\" alt=\"\" class=\"wp-image-8087\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2024\/04\/image-2.png 585w, https:\/\/white-night.club\/wp-content\/uploads\/2024\/04\/image-2-300x229.png 300w\" sizes=\"(max-width: 585px) 100vw, 585px\" \/><\/figure>\n\n\n\n<p>\u6700\u540e\u53d1\u73b0\u786e\u5b9e\u662f\u201c\u611f\u89c9\u53ef\u4ee5\u201d\uff0c\u60f3\u4e86\u534a\u5929\u5c31\u60f3\u51fa\u628aEXISTS\u6362\u6210IN\u53bb\u5224\u65ad\uff0c\u80fd\u5feb\u4e2a\u51e0\u767ems\ud83d\ude22<\/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(2 * 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 A.employee_id,A.name,A.salary,\ndense_rank()over(ORDER BY A.salary ASC) AS team_id\nFROM Employees AS A\nWHERE A.salary in(\n    SELECT salary\n    FROM Employees\n    GROUP BY salary \n    HAVING COUNT(salary)&gt;1\n)\nORDER BY team_id ASC,employee_id ASC;\" 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\"> A.employee_id,A.name,A.salary,<\/span><\/span>\n<span class=\"line\"><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\"> A.salary <\/span><span style=\"color: #569CD6\">ASC<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> team_id<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Employees <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> A<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> A.salary <\/span><span style=\"color: #569CD6\">in<\/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>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Employees<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">GROUP BY<\/span><span style=\"color: #D4D4D4\"> salary <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">HAVING<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">COUNT<\/span><span style=\"color: #D4D4D4\">(salary)&gt;<\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ORDER BY<\/span><span style=\"color: #D4D4D4\"> team_id <\/span><span style=\"color: #569CD6\">ASC<\/span><span style=\"color: #D4D4D4\">,employee_id <\/span><span style=\"color: #569CD6\">ASC<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>EXISTS\/IN<\/p>\n","protected":false},"author":1,"featured_media":8087,"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\/8086"}],"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=8086"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/8086\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/8087"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=8086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=8086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=8086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}