{"id":245209,"date":"2022-06-27T09:23:15","date_gmt":"2022-06-27T01:23:15","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=245209"},"modified":"2022-06-19T12:23:52","modified_gmt":"2022-06-19T04:23:52","slug":"datastore-platform-record","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/datastore-platform-record.html","title":{"rendered":"\u5982\u4f55\u5728\u4e0d\u540c\u7684\u6570\u636e\u5e73\u53f0\u53d6\u524d\u767e\u5206\u4e4bN\u7684\u8bb0\u5f55\uff1f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u200b\u6700\u8fd1\u5e2e\u4e1a\u52a1\u90e8\u95e8\u68b3\u7406\u4e1a\u52a1\u62a5\u8868\uff0c\u5176\u4e2d\u6709\u4e2a\u9700\u6c42\u662f\u5c31\u7b97\u67d0\u6307\u6807\u7b49\u5f85\u65f6\u95f4\u6700\u957f\u7684\u524d\u767e\u5206\u4e4b\u5341\uff0c\u5176\u5b9e\u5c31\u662f\u5bf9\u7b49\u5f85\u65f6\u957f\u8fdb\u884c\u5012\u5e8f\u6392\u5e8f\u540e\uff0c\u53d6\u7ed3\u679c\u96c6\u7684\u524d\u767e\u5206\u4e4b\u5341\u3002\u8fd9\u4e2a\u9700\u6c42\u5728SQL Server\u548cOracle\u4e0a\u90fd\u5f88\u5bb9\u6613\u5b9e\u73b0\uff0c\u751a\u81f3\u662f\u5728MySQL 8.0\u4e5f\u5f88\u5bb9\u6613\u5b9e\u73b0\uff0c\u53ea\u662f\u6070\u597d\u6211\u4eec\u4e1a\u52a1\u6570\u636e\u5e93\u662fMySQL 5.7\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5148\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e0b\u4e0d\u540c\u6570\u636e\u5e93\u5e73\u53f0\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n

SQL Server\u5b9e\u73b0\u65b9\u6cd5<\/strong><\/div>\n

SQL Server\u4e0a\u6709\u4e2aTOP Percent\u7684\u65b9\u6cd5\u53ef\u4ee5\u76f4\u63a5\u53d6\u7ed3\u679c\u7684\u524d\uff08\u6216\u540e\uff09\u767e\u5206\u4e4bN\u3002<\/p>\n

\u4f8b\u5982\u6709\u5982\u4e0b\u4e00\u5f20City\u8868\uff1a<\/p>\n

\"\"<\/p>\n

\u6211\u4eec\u53d6\u524d10%\u7684\u6570\u636e\u8bb0\u5f55\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n

SELECT \r\nTOP 10 PERCENT  \r\n*\r\nFROM City\r\nORDER BY ID DESC<\/pre>\n

\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

\"\"<\/p>\n

Oracle\u5b9e\u73b0\u65b9\u6cd5<\/strong><\/div>\n

Oracle\u6709\u4e2aROWNUM\u4f2a\u5217\u53ef\u4ee5\u7528\u6765\u5e2e\u52a9\u6211\u4eec\u8ba1\u7b97\u524d\u767e\u5206\u4e4bN\u3002<\/p>\n

ROWNUM\u4f2a\u5217\u7684\u7279\u70b9\uff1a<\/p>\n

  • ROWNUM\u662f\u6309\u7167\u8bb0\u5f55\u63d2\u5165\u65f6\u7684\u987a\u5e8f\u6392\u5e8f\u7684\u3002<\/li>\n
  • ROWNUM\u5e76\u4e0d\u5b9e\u9645\u5b58\u5728\uff0c\u662f\u5bf9\u7b5b\u9009\u540e\u7684\u7ed3\u679c\u96c6\u7684\u4e00\u4e2a\u6392\u5e8f\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u7ed3\u679c\u96c6\u5c31\u4e0d\u4f1a\u6709ROWNUM\u3002<\/li>\n
  • ROWNUM\u4e0d\u80fd\u7528\u57fa\u8868\u540d\u4f5c\u4e3a\u524d\u7f00\u3002<\/li>\n

    \u5728\u4f7f\u7528ROWNUM\u8fdb\u884c\u67e5\u8be2\u65f6\uff0c\u8bf7\u6ce8\u610f\uff1a<\/p>\n

  • \u82e5\u4f7f\u7528\u5927\u4e8e\u53f7(>),\u5219\u53ea\u80fd\u4f7f\u7528\uff08>0\uff09,\u5176\u4ed6\u5747\u4e0d\u53ef\u4ee5 \u3002<\/li>\n
  • \u82e5\u4f7f\u7528\u5c0f\u4e8e\u53f7\uff08<\uff09\uff0c\u540c\u4e00\u822c\u60c5\u51b5 \u3002<\/li>\n
  • \u82e5\u4f7f\u7528\u7b49\u4e8e\u53f7\uff08=\uff09\uff0c\u5219\u53ea\u80fd\u4f7f\u7528\u7b49\u4e8e1\uff08=1\uff09\u6211\u4eec\u53ef\u4ee5\u5148\u8ba1\u7b97\u51fa\u6574\u4e2a\u8868\u7684\u8bb0\u5f55\u884c\u6570\u91cf\u3002<\/li>\n
    SELECT COUNT(*) CNT FROM City<\/pre>\n

    \u7136\u540e\u6839\u636ecount\u805a\u5408\u67e5\u8be2\u603b\u6761\u6570\u4e58\u4ee5\u767e\u5206\u6bd4\uff0c\u6765\u786e\u5b9a\u8981\u67e5\u8be2\u7684\u6761\u6570\u3002<\/p>\n

    SELECT 0.1*COUNT(*) CNT FROM City<\/pre>\n

    \u6700\u540e\u53d6\u51fa\u4f2a\u5217\u5c0f\u4e8e\u5171\u6709\u6570\u636e\u7684\u767e\u5206\u6bd4\u7684\u6570\u636e\u3002<\/p>\n

    SELECT * FROM CITY\r\nWHERE ID IN\r\n(\r\nSELECT ID FROM \r\n(\r\nSELECT ID FROM CITY ORDER BY ID DESC\r\n)\r\nWHERE ROWNUM < (SELECT COUNT(*)*0.1 FROM CITY)<\/pre>\n

    \u6ce8\u610f\uff1aOracle\u4e0d\u652f\u6301\u5b50\u67e5\u8be2\u5185ORDER BY\uff0c\u9700\u8981\u5728\u5916\u9762\u518d\u5d4c\u5957\u4e00\u5c42\u3002<\/p>\n

    MySQL 8.0\u7684\u5b9e\u73b0\u65b9\u6cd5<\/strong><\/div>\n

    MySQL 8.0\u7684\u5b9e\u73b0\u65b9\u6cd5\u4e3b\u8981\u662f\u501f\u52a9\u7a97\u53e3\u51fd\u6570ROW_NUMBER() OVER()\u3002\u5176\u5b9e\u5c31\u662f\u7ed9\u6392\u597d\u5e8f\u7684\u96c6\u5408\u6dfb\u52a0\u4e00\u4e2a\u81ea\u589e\u957f\u5217\uff0c\u4e0eOracle\u7684ROWNUM\u6709\u70b9\u7c7b\u4f3c\u3002<\/p>\n

    SELECT * FROM\r\n(\r\nSELECT *,\r\nROW_NUMBER() OVER(ORDER BY ID DESC) rn\r\nFROM  City\r\nORDER BY ID DESC\r\n) a\r\nWHERE a.rn<=(SELECT 0.1*COUNT(*) FROM City)<\/pre>\n
    MySQL 5.X\u7684\u5b9e\u73b0\u65b9\u6cd5<\/strong><\/div>\n

    \u6211\u4eec\u77e5\u9053MySQL 5.X\u662f\u6ca1\u6709\u5f00\u7a97\u51fd\u6570ROW_NUMBER() OVER()\u7684\uff0c\u90a3\u8be5\u5982\u4f55\u5b9e\u73b0\u5462\uff1f<\/p>\n

    \u8fd9\u91cc\u6211\u4eec\u9700\u8981\u501f\u52a9\u53d8\u91cf\u6765\u5b9e\u73b0\uff0c\u5176\u5b9e\u601d\u8def\u8fd8\u662f\u521b\u5efa\u4e00\u4e2a\u81ea\u589e\u957f\u5217\uff0c\u53ea\u662f\u65b9\u6cd5\u4e0d\u540c\u3002<\/p>\n

    SELECT \r\n  A.*,\r\n  @row_num:=@row_num+1 AS ROW_NUM\r\nFROM \r\n  City A , (SELECT @row_num:=0) B\r\nORDER BY ID DESC<\/pre>\n

    \u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u4e00\u5f20\u6709\u81ea\u589e\u957f\u5217\u7684\u7ed3\u679c\u96c6\u4e86\uff0c\u63a5\u4e0b\u6765\u8fd8\u662f\u6309\u7167\u4e0a\u9762\u7c7b\u4f3c\u7684\u65b9\u6cd5\uff0c\u53d6\u524d10%\u5373\u53ef\u3002<\/p>\n

    SELECT * FROM\r\n(\r\nSELECT \r\n  A.*,\r\n  @row_num:=@row_num+1 AS ROW_NUM\r\nFROM \r\n  City A , (SELECT @row_num:=0) B\r\nORDER BY ID DESC\r\n) C\r\nWHERE C.ROW_NUM<=(@row_num*0.1)<\/pre>\n

    \u5176\u5b9eMySQL 5.X\u4e5f\u633a\u7b80\u5355\u7684\uff0c\u53ea\u662f\u5f53\u65f6\u4e0d\u600e\u4e48\u60f3\u7528\u53d8\u91cf\uff0c\u60f3\u770b\u770b\u6709\u6ca1\u6709\u5176\u4ed6\u529e\u6cd5\uff0c\u6700\u540e\u53d1\u73b0\u8fd8\u662f\u5f97\u7528\u53d8\u91cf\u3002<\/p>\n

    \u4ee5\u4e0a\u5c31\u662f\u4e0d\u540c\u5e73\u53f0\u7684\u6570\u636e\u5e93\u6c42\u524d\u767e\u5206\u4e4bN\u7684\u65b9\u6cd5\u4e86\uff0c\u4ee3\u7801\u53ef\u4ee5\u9a8c\u8bc1\u4e00\u4e0b\u6536\u85cf\u8d77\u6765\u7559\u7740\u4e0b\u6b21\u76f4\u63a5\u5957\u7528\u3002<\/p>\n

    \u603b\u7ed3<\/strong><\/div>\n

    \u5176\u4e2d\u6709\u6d89\u53ca\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u9700\u8981\u5c0f\u4f19\u4f34\u4eec\u81ea\u5df1\u53bb\u8fdb\u4e00\u6b65\u4e86\u89e3\uff1a<\/p>\n

  • SQL Server\u7684TOP PERCENT\u3002<\/li>\n
  • Oracle\u7684ROWNUM\uff0c\u5b50\u67e5\u8be2\u6392\u5e8f\u3002<\/li>\n
  • ROW_NUMBER() OVER()\u3002<\/li>\n
  • MySQL\u7684\u53d8\u91cf\u200b\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"

    \u5148\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e0b\u4e0d\u540c\u6570\u636e\u5e93\u5e73\u53f0\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002 SQL Server\u4e0a\u6709\u4e2aTOP Percent\u7684\u65b9\u6cd5\u53ef\u4ee5\u76f4\u63a5\u53d6\u7ed3\u679c […]<\/p>\n","protected":false},"author":1920,"featured_media":163226,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-245209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/245209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1920"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=245209"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/245209\/revisions"}],"predecessor-version":[{"id":245212,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/245209\/revisions\/245212"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/163226"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=245209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=245209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=245209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}