{"id":7046,"date":"2024-11-14T09:25:13","date_gmt":"2024-11-14T01:25:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7046\/"},"modified":"2024-11-14T09:25:13","modified_gmt":"2024-11-14T01:25:13","slug":"sql-%e4%b8%ad-ntile-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e5%88%92%e5%88%86%e6%a0%b7%e6%9c%ac%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7046\/","title":{"rendered":"SQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173035045648071.jpg\" class=\"aligncenter\" title=\"SQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\uff1f\u63d2\u56fe\" alt=\"SQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>ntile \u5982\u4f55\u5bf9\u6837\u672c\u8fdb\u884c\u5212\u5206\uff1f<\/strong><\/p>\n<p>\u5728 sql \u4e2d\uff0cntile \u51fd\u6570\u53ef\u5c06\u4e00\u7ec4\u6570\u636e\u6309\u964d\u5e8f\u6216\u5347\u5e8f\u5206\u914d\u5230\u6307\u5b9a\u6570\u91cf\u7684\u7ec4\u522b\u4e2d\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7c7b\u6216\u5206\u7ec4\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u8ff0\u67e5\u8be2\u5c06\u5458\u5de5\u8868\u4e2d\u7684\u85aa\u8d44\u6570\u636e\u5212\u5206\u4e3a 10 \u4e2a\u7ec4\u522b\uff0c\u5e76\u6309\u964d\u5e8f\uff1a<\/p>\n<pre>select\n    salary,\n    ntile(10) over(\n    order by salary desc)\nfrom\n    salaries\nwhere\n    salary &gt;= 150000<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5bf9\u4e8e 36 \u4e2a\u6837\u672c\uff0c10 \u7b49\u5206\uff0cntile \u51fd\u6570\u7684\u5212\u5206\u89c4\u5219\u4e3a\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u6837\u672c\u603b\u6570\u4e0d\u80fd\u88ab\u5206\u7ec4\u6570\u6574\u9664\uff0c\u5219\u9009\u62e9\u5c0f\u4e8e\u6837\u672c\u603b\u6570\u7684\u6700\u5927\u80fd\u88ab\u5206\u7ec4\u6570\u6574\u9664\u7684\u6570\u5b57\u8fdb\u884c\u5206\u7ec4\u3002<\/li>\n<li>\u4f8b\u5982\uff0c36 \u4e0d\u80fd\u88ab 10 \u6574\u9664\uff0c\u56e0\u6b64\u9009\u62e9\u5c0f\u4e8e 36 \u7684\u6700\u5927\u80fd\u88ab 10 \u6574\u9664\u7684\u6570\u5b57 30\u3002<\/li>\n<li>\u6bcf\u7ec4\u5305\u542b 3 \u4e2a\u6837\u672c\u3002<\/li>\n<li>\u4ece\u524d\u5f80\u540e\u6bcf\u7ec4\u8865\u5145 1 \u4e2a\u6837\u672c\uff0c\u76f4\u81f3\u6837\u672c\u603b\u6570\u4e3a 36\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fSQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ntile \u5982\u4f55\u5bf9\u6837\u672c\u8fdb\u884c\u5212\u5206\uff1f \u5728 sql \u4e2d\uff0cntile \u51fd\u6570\u53ef\u5c06\u4e00\u7ec4\u6570\u636e\u6309\u964d\u5e8f\u6216\u5347\u5e8f\u5206\u914d\u5230\u6307\u5b9a\u6570\u91cf\u7684\u7ec4\u522b\u4e2d\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7c7b\u6216\u5206\u7ec4\u3002 \u4f8b\u5982\uff0c\u4e0b\u8ff0\u67e5\u8be2\u5c06\u5458\u5de5\u8868\u4e2d\u7684\u85aa\u8d44\u6570\u636e\u5212\u5206\u4e3a 10 \u4e2a\u7ec4\u522b\uff0c\u5e76\u6309\u964d\u5e8f\uff1a select salary, ntile(10) over( order by salary desc) from salaries where salary &gt;= 150000 \u767b\u5f55\u540e\u590d\u5236 \u5bf9\u4e8e 36 \u4e2a\u6837\u672c\uff0c10 \u7b49\u5206\uff0cntile \u51fd\u6570\u7684\u5212\u5206\u89c4\u5219\u4e3a\uff1a \u5982\u679c\u6837\u672c\u603b\u6570\u4e0d\u80fd\u88ab\u5206\u7ec4\u6570\u6574\u9664\uff0c\u5219\u9009\u62e9\u5c0f\u4e8e\u6837\u672c\u603b\u6570\u7684\u6700\u5927\u80fd\u88ab\u5206\u7ec4\u6570\u6574\u9664\u7684\u6570\u5b57\u8fdb\u884c\u5206\u7ec4\u3002 \u4f8b\u5982\uff0c36 \u4e0d\u80fd\u88ab 10 \u6574\u9664\uff0c\u56e0\u6b64\u9009\u62e9\u5c0f\u4e8e 36 \u7684\u6700\u5927\u80fd\u88ab 10 \u6574\u9664\u7684\u6570\u5b57 30\u3002 \u6bcf\u7ec4\u5305\u542b 3 \u4e2a\u6837\u672c\u3002 \u4ece\u524d\u5f80\u540e\u6bcf\u7ec4\u8865\u5145 1 \u4e2a\u6837\u672c\uff0c\u76f4\u81f3\u6837\u672c\u603b\u6570\u4e3a 36\u3002 \u4ee5\u4e0a\u5c31\u662fSQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7046","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7046"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7046\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}