{"id":6765,"date":"2024-11-14T08:57:49","date_gmt":"2024-11-14T00:57:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6765\/"},"modified":"2024-11-14T08:57:49","modified_gmt":"2024-11-14T00:57:49","slug":"%e5%a6%82%e4%bd%95%e9%ab%98%e6%95%88%e5%9c%b0%e5%af%b9%e5%a4%a7%e5%9e%8b-mysql-%e8%a1%a8%e6%95%b0%e6%8d%ae%e8%bf%9b%e8%a1%8c%e9%9a%8f%e6%9c%ba%e6%8e%92%e5%ba%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6765\/","title":{"rendered":"\u5982\u4f55\u9ad8\u6548\u5730\u5bf9\u5927\u578b MySQL \u8868\u6570\u636e\u8fdb\u884c\u968f\u673a\u6392\u5e8f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172991072825596.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u9ad8\u6548\u5730\u5bf9\u5927\u578b MySQL \u8868\u6570\u636e\u8fdb\u884c\u968f\u673a\u6392\u5e8f\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u9ad8\u6548\u5730\u5bf9\u5927\u578b MySQL \u8868\u6570\u636e\u8fdb\u884c\u968f\u673a\u6392\u5e8f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u968f\u673a\u6253\u4e71  \u8868\u7684\u6570\u636e<\/strong><\/p>\n<p>\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u5bf9\u8868\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u6309\u63d2\u5165\u987a\u5e8f\u6392\u5e8f\u975e\u5e38\u4f4e\u6548\u3002\u5982\u679c\u60a8\u5e0c\u671b\u91cd\u65b0\u8868\u4e2d\u7684\u6570\u636e\u4ee5\u4fbf\u968f\u673a\u6392\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u5b50\u67e5\u8be2<\/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\uff1a\u5e38\u89c4\u5199\u6cd5<\/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>\u65b9\u6cd5 1 \u4f7f\u7528\u5b50\u67e5\u8be2\u6765\u4ece\u8868\u4e2d\u9009\u62e9\u4e00\u4e2a\u968f\u673a\u6392\u5e8f\u7684 id \u5217\u8868\uff0c\u7136\u540e\u5c06\u5176\u4e0e\u4e3b\u8868\u8fdb\u884c\u8054\u63a5\u3002\u8fd9\u79cd\u65b9\u6cd5\u6027\u80fd\u66f4\u597d\u3002<\/p>\n<p>\u65b9\u6cd5 2 \u662f mysql \u7684\u5e38\u89c4\u5199\u6cd5\u3002\u867d\u7136\u5b83\u66f4\u5bb9\u6613\u7406\u89e3\uff0c\u4f46\u5f53\u6570\u636e\u96c6\u8f83\u5927\u65f6\u6027\u80fd\u4f1a\u4e0b\u964d\u3002<\/p>\n<p>\u8bf7\u6ce8\u610f\uff0crand() \u51fd\u6570\u4f1a\u751f\u6210\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u56e0\u6b64\u7ed3\u679c\u4e0d\u4f1a\u771f\u6b63\u968f\u673a\u3002\u5982\u679c\u9700\u8981\u771f\u6b63\u7684\u968f\u673a\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528\u8bf8\u5982 uuid \u4e4b\u7c7b\u7684\u503c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u9ad8\u6548\u5730\u5bf9\u5927\u578b MySQL \u8868\u6570\u636e\u8fdb\u884c\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>\u968f\u673a\u6253\u4e71 \u8868\u7684\u6570\u636e \u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u5bf9\u8868\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u6309\u63d2\u5165\u987a\u5e8f\u6392\u5e8f\u975e\u5e38\u4f4e\u6548\u3002\u5982\u679c\u60a8\u5e0c\u671b\u91cd\u65b0\u8868\u4e2d\u7684\u6570\u636e\u4ee5\u4fbf\u968f\u673a\u6392\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u65b9\u6cd5 1\uff1a\u5b50\u67e5\u8be2 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\uff1a\u5e38\u89c4\u5199\u6cd5 SELECT * FROM student WHERE totalScore BETWEEN 5 AND 100 ORDER BY RAND() LIMIT 100; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 1 [&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-6765","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6765","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=6765"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6765\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}