{"id":6770,"date":"2024-11-14T08:42:21","date_gmt":"2024-11-14T00:42:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6770\/"},"modified":"2024-11-14T08:42:21","modified_gmt":"2024-11-14T00:42:21","slug":"%e5%a6%82%e4%bd%95%e6%89%93%e4%b9%b1mysql%e8%a1%a8%e4%b8%ad%e6%8c%89%e6%8f%92%e5%85%a5%e9%a1%ba%e5%ba%8f%e6%8e%92%e5%88%97%e7%9a%84%e6%95%b0%e6%8d%ae%ef%bc%8c%e4%bd%bf%e5%85%b6%e9%9a%8f%e6%9c%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6770\/","title":{"rendered":"\u5982\u4f55\u6253\u4e71MySQL\u8868\u4e2d\u6309\u63d2\u5165\u987a\u5e8f\u6392\u5217\u7684\u6570\u636e\uff0c\u4f7f\u5176\u968f\u673a\u6392\u5e8f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172991232499129.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u6253\u4e71MySQL\u8868\u4e2d\u6309\u63d2\u5165\u987a\u5e8f\u6392\u5217\u7684\u6570\u636e\uff0c\u4f7f\u5176\u968f\u673a\u6392\u5e8f\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u6253\u4e71MySQL\u8868\u4e2d\u6309\u63d2\u5165\u987a\u5e8f\u6392\u5217\u7684\u6570\u636e\uff0c\u4f7f\u5176\u968f\u673a\u6392\u5e8f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6570\u636e\u987a\u5e8f\u6253\u4e71<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u6253\u4e71mysql\u8868\u4e2d\u6309\u63d2\u5165\u987a\u5e8f\u76841\u4e07\u6761\u6570\u636e\u7684\u987a\u5e8f\uff0c\u4f7f\u5176\u968f\u673a\u6392\u5e8f\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528sql\u67e5\u8be2\u8bed\u53e5\u6765\u6253\u4e71\u6570\u636e\u987a\u5e8f\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1:<\/strong><\/p>\n<pre>select *\nfrom test1 as u\ninner join (select id from test1 where totalscore between 5 and 100 order by rand() limit 100) as t on t.id=u.id\nwhere 1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2:<\/strong><\/p>\n<pre>SELECT * FROM student WHERE totalScore BETWEEN 5 AND 100 ORDER BY RAND() LIMIT 100;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a<\/strong>\u4f7f\u7528inner join\u5b50\u67e5\u8be2\uff0c\u4ece\u8868test1\u4e2d\u968f\u673a\u9009\u62e9100\u6761\u6570\u636e\uff08totalscore\u57285\u548c100\u4e4b\u95f4\uff09\u4f5c\u4e3a\u968f\u673a\u987a\u5e8f\u8868\uff0c\u7136\u540e\u4e0e\u4e3b\u8868test1\u8fdb\u884c\u8fde\u63a5\u3002<\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a<\/strong>\u4f7f\u7528\u5e38\u89c4\u7684order by rand()\u8bed\u53e5\uff0c\u5bf9\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u8fdb\u884c\u968f\u673a\u6392\u5e8f\uff0c\u5e76\u9650\u5236\u8fd4\u56de100\u6761\u6570\u636e\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u65b9\u6cd5 1 \u7684\u6027\u80fd\u4f18\u4e8e\u65b9\u6cd5 2\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u5b50\u67e5\u8be2\u5728\u968f\u673a\u8868\u4e2d\u9884\u5148\u9009\u62e9\u6709\u9650\u7684\u6570\u636e\u96c6\uff0c\u7136\u540e\u8fdb\u884c\u8fde\u63a5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u6253\u4e71MySQL\u8868\u4e2d\u6309\u63d2\u5165\u987a\u5e8f\u7684\u6570\u636e\uff0c\u4f7f\u5176\u968f\u673a\u6392\u5e8f\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>\u6570\u636e\u987a\u5e8f\u6253\u4e71 \u95ee\u9898\uff1a \u5982\u4f55\u6253\u4e71mysql\u8868\u4e2d\u6309\u63d2\u5165\u987a\u5e8f\u76841\u4e07\u6761\u6570\u636e\u7684\u987a\u5e8f\uff0c\u4f7f\u5176\u968f\u673a\u6392\u5e8f\uff1f \u56de\u7b54\uff1a \u53ef\u4ee5\u4f7f\u7528sql\u67e5\u8be2\u8bed\u53e5\u6765\u6253\u4e71\u6570\u636e\u987a\u5e8f\uff1a \u65b9\u6cd5 1: select * from test1 as u inner join (select id from test1 where totalscore between 5 and 100 order by rand() limit 100) as t on t.id=u.id where 1 \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2: SELECT * FROM student WHERE totalScore BETWEEN 5 AND 100 ORDER BY RAND() LIMIT 100; \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/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-6770","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6770","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=6770"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6770\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}