{"id":200845,"date":"2025-05-06T14:04:19","date_gmt":"2025-05-06T06:04:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200845\/"},"modified":"2025-05-06T14:04:19","modified_gmt":"2025-05-06T06:04:19","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%e9%9b%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200845\/","title":{"rendered":"SQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\u96c6\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>SQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\u96c6\uff1f <\/h1>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u4e3b\u673a\u5b9d\u8d1d\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241117\/173180470767393e23dc6a5.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>sql \u4e2d ntile \u51fd\u6570\u7684\u6837\u672c\u5212\u5206\u89c4\u5219<\/strong><\/p>\n<p>ntile \u51fd\u6570\u7528\u4e8e\u5c06\u6570\u636e\u6837\u672c\u96c6\u5747\u5300\u5730\u5212\u5206\u4e3a\u6307\u5b9a\u6570\u91cf\u7684\u7ec4\u3002\u5728\u7ed9\u5b9a\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5bf9\u5176\u884c\u4e3a\u8fdb\u884c\u4e86\u89e3\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>\u8fd9\u4e2a\u67e5\u8be2\u5c06 36 \u4e2a\u6837\u672c\u5212\u5206\u4e3a 10 \u7b49\u4efd\uff0c\u7136\u800c\uff0c\u67d0\u4e9b\u7ec4\u5305\u542b 4 \u4e2a\u6837\u672c\uff0c\u800c\u53e6\u4e00\u4e9b\u7ec4\u4ec5\u5305\u542b 3 \u4e2a\u6837\u672c\u3002<\/p>\n<p>\u7ecf\u8fc7\u53cd\u590d\u5b9e\u9a8c\uff0c\u6211\u4eec\u5f97\u51fa\u4e86\u4ee5\u4e0b\u5212\u5206\u89c4\u5219\uff1a<\/p>\n<p>\u5f53\u6837\u672c\u603b\u6570 n \u4e0d\u80fd\u88ab\u5206\u7ec4\u6570 g \u6574\u9664\u65f6\uff0cntile \u51fd\u6570\u4f1a\u9009\u62e9\u5c0f\u4e8en\u7684\u6700\u5927\u80fd\u88abg\u6574\u9664\u7684\u6570\u5b57\u8fdb\u884c\u5206\u7ec4\u3002<\/p>\n<p>\u5728\u793a\u4f8b\u4e2d\uff0c36 \u4e0d\u80fd\u88ab 10 \u6574\u9664\uff0c\u56e0\u6b64 ntile \u51fd\u6570\u9009\u62e9\u4e86\u5c0f\u4e8e 36 \u7684\u6700\u5927\u80fd\u88ab 10 \u6574\u9664\u7684\u6570\u5b57 30 \u8fdb\u884c\u5206\u7ec4\u3002\u56e0\u6b64\uff0c\u6bcf\u7ec4\u6700\u521d\u5305\u542b 3 \u4e2a\u6837\u672c\u3002<\/p>\n<p>\u4e4b\u540e\uff0cntile \u51fd\u6570\u4ece\u524d\u5f80\u540e\u9010\u4e2a\u7ec4\u8865\u5145 1 \u4e2a\u6837\u672c\uff0c\u76f4\u81f3\u6837\u672c\u603b\u6570\u8fbe\u5230 36\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aSQL \u4e2d ntile \u51fd\u6570\u5982\u4f55\u5212\u5206\u6837\u672c\u96c6\uff1f \u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>SQL \u4e2d ntile \u51fd\u6570\u5982\u4f55&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200845","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200845"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200845\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}