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>\nMySQL 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>\nMySQL 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>\nOracle\u7684ROWNUM\uff0c\u5b50\u67e5\u8be2\u6392\u5e8f\u3002<\/li>\nROW_NUMBER() OVER()\u3002<\/li>\nMySQL\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}]}}