{"id":5156,"date":"2024-09-26T17:01:03","date_gmt":"2024-09-26T09:01:03","guid":{"rendered":""},"modified":"2024-09-26T17:01:03","modified_gmt":"2024-09-26T09:01:03","slug":"mysql\u67e5\u8be2\u8bed\u53e5\u8be6\u89e3_mysql\u57fa\u672c\u8bed\u53e5","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5156.html","title":{"rendered":"mysql\u67e5\u8be2\u8bed\u53e5\u8be6\u89e3_mysql\u57fa\u672c\u8bed\u53e5"},"content":{"rendered":"
\n

\"mysql\u67e5\u8be2\u8bed\u53e5\u8be6\u89e3_mysql\u57fa\u672c\u8bed\u53e5<\/p>\n

\"mysql\u67e5\u8be2\u8bed\u53e5\u8be6\u89e3_mysql\u57fa\u672c\u8bed\u53e5<\/p>\n

\u95ee\uff1aMySQL\u4e2d\u7b80\u5355\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5199\uff1f<\/p>\n

\u8003\u65e0\u5fe7\u5c0f\u7f16\u89e3\u7b54\uff1a\u7b80\u5355\u67e5\u8be2<\/p>\n

\u7b80\u5355\u7684Transact-SQL\u67e5\u8be2\u53ea\u5305\u62ec\u9009\u62e9\u5217\u8868\u3001FROM\u5b50\u53e5\u548cWHERE\u5b50\u53e5\u3002\u5b83\u4eec\u5206\u522b\u8bf4\u660e\u6240\u67e5\u8be2\u5217\u3001\u67e5\u8be2\u7684<\/p>\n

\u8868\u6216\u89c6\u56fe\u3001\u4ee5\u53ca\u641c\u7d22\u6761\u4ef6\u7b49\u3002<\/p>\n

\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u8bed\u53e5\u67e5\u8be2testtable\u8868\u4e2d\u59d3\u540d\u4e3a\u201c\u5f20\u4e09\u201d\u7684nickname\u5b57\u6bb5\u548cemail\u5b57\u6bb5\u3002<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT `nickname`,`email`FROM `testtable`WHERE `name`='\u5f20\u4e09'<\/p>\n

(\u4e00) \u9009\u62e9\u5217\u8868<\/p>\n

\u9009\u62e9\u5217\u8868(select_list)\u6307\u51fa\u6240\u67e5\u8be2\u5217\uff0c\u5b83\u53ef\u4ee5\u662f\u4e00\u7ec4\u5217\u540d\u5217\u8868\u3001\u661f\u53f7\u3001\u8868\u8fbe\u5f0f\u3001\u53d8\u91cf(\u5305\u62ec\u5c40\u90e8\u53d8\u91cf\u548c\u5168\u5c40\u53d8\u91cf)\u7b49\u6784\u6210\u3002<\/p>\n

1\u3001\u9009\u62e9\u6240\u6709\u5217<\/p>\n

\u4f8b\u5982\uff0c\u4e0b\u9762\u8bed\u53e5\u663e\u793atesttable\u8868\u4e2d\u6240\u6709\u5217\u7684\u6570\u636e\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT * FROM testtable<\/p>\n

2\u3001\u9009\u62e9\u90e8\u5206\u5217\u5e76\u6307\u5b9a\u5b83\u4eec\u7684\u663e\u793a\u6b21\u5e8f<\/p>\n

\u67e5\u8be2\u7ed3\u679c\u96c6\u5408\u4e2d\u6570\u636e\u7684\u6392\u5217\u987a\u5e8f\u4e0e\u9009\u62e9\u5217\u8868\u4e2d\u6240\u6307\u5b9a\u7684\u5217\u540d\u6392\u5217\u987a\u5e8f\u76f8\u540c\u3002<\/p>\n

\u4f8b\u5982\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT nickname,email FROM testtable<\/p>\n

3\u3001\u66f4\u6539\u5217\u6807\u9898<\/p>\n

\u5728\u9009\u62e9\u5217\u8868\u4e2d\uff0c\u53ef\u91cd\u65b0\u6307\u5b9a\u5217\u6807\u9898\u3002\u5b9a\u4e49\u683c\u5f0f\u4e3a\uff1a<\/p>\n

\u5217\u6807\u9898=\u5217\u540d<\/p>\n

\u5217\u540d \u5217\u6807\u9898<\/p>\n

\u5982\u679c\u6307\u5b9a\u7684\u5217\u6807\u9898\u4e0d\u662f\u6807\u51c6\u7684\u6807\u8bc6\u7b26\u683c\u5f0f\u65f6\uff0c\u5e94\u4f7f\u7528\u5f15\u53f7\u5b9a\u754c\u7b26\uff0c\u4f8b\u5982\uff0c\u4e0b\u5217\u8bed\u53e5\u4f7f\u7528\u6c49\u5b57\u663e\u793a\u5217<\/p>\n

\u6807\u9898\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT \u6635\u79f0=nickname,\u7535\u5b50\u90ae\u4ef6=emailFROM testtable<\/p>\n

4\u3001\u5220\u9664\u91cd\u590d\u884c<\/p>\n

SELECT\u8bed\u53e5\u4e2d\u4f7f\u7528ALL\u6216DISTINCT\u9009\u9879\u6765\u663e\u793a\u8868\u4e2d\u7b26\u5408\u6761\u4ef6\u7684\u6240\u6709\u884c\u6216\u5220\u9664\u5176\u4e2d\u91cd\u590d\u7684\u6570\u636e\u884c\uff0c\u9ed8\u8ba4<\/p>\n

\u4e3aALL\u3002\u4f7f\u7528DISTINCT\u9009\u9879\u65f6\uff0c\u5bf9\u4e8e\u6240\u6709\u91cd\u590d\u7684\u6570\u636e\u884c\u5728SELECT\u8fd4\u56de\u7684\u7ed3\u679c\u96c6\u5408\u4e2d\u53ea\u4fdd\u7559\u4e00\u884c\u3002<\/p>\n

5\u3001\u9650\u5236\u8fd4\u56de\u7684\u884c\u6570<\/p>\n

\u4f7f\u7528TOP n [PERCENT]\u9009\u9879\u9650\u5236\u8fd4\u56de\u7684\u6570\u636e\u884c\u6570\uff0cTOP n\u8bf4\u660e\u8fd4\u56den\u884c\uff0c\u800cTOP n PERCENT\u65f6\uff0c\u8bf4\u660en\u662f<\/p>\n

\u8868\u793a\u4e00\u767e\u5206\u6570\uff0c\u6307\u5b9a\u8fd4\u56de\u7684\u884c\u6570\u7b49\u4e8e\u603b\u884c\u6570\u7684\u767e\u5206\u4e4b\u51e0\u3002<\/p>\n

\u4f8b\u5982\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT TOP 2 * FROM `testtable`<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT TOP 20 PERCENT * FROM `testtable`<\/p>\n

(\u4e8c) FROM\u5b50\u53e5<\/p>\n

FROM\u5b50\u53e5\u6307\u5b9aSELECT\u8bed\u53e5\u67e5\u8be2\u53ca\u4e0e\u67e5\u8be2\u76f8\u5173\u7684\u8868\u6216\u89c6\u56fe\u3002\u5728FROM\u5b50\u53e5\u4e2d\u6700\u591a\u53ef\u6307\u5b9a256\u4e2a\u8868\u6216\u89c6\u56fe\uff0c<\/p>\n

\u5b83\u4eec\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\u3002<\/p>\n

\u5728FROM\u5b50\u53e5\u540c\u65f6\u6307\u5b9a\u591a\u4e2a\u8868\u6216\u89c6\u56fe\u65f6\uff0c\u5982\u679c\u9009\u62e9\u5217\u8868\u4e2d\u5b58\u5728\u540c\u540d\u5217\uff0c\u8fd9\u65f6\u5e94\u4f7f\u7528\u5bf9\u8c61\u540d\u9650\u5b9a\u8fd9\u4e9b\u5217<\/p>\n

\u6240\u5c5e\u7684\u8868\u6216\u89c6\u56fe\u3002\u4f8b\u5982\u5728usertable\u548ccitytable\u8868\u4e2d\u540c\u65f6\u5b58\u5728cityid\u5217\uff0c\u5728\u67e5\u8be2\u4e24\u4e2a\u8868\u4e2d\u7684cityid\u65f6\u5e94<\/p>\n

\u4f7f\u7528\u4e0b\u9762\u8bed\u53e5\u683c\u5f0f\u52a0\u4ee5\u9650\u5b9a\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT `username`,citytable.cityid<\/p>\n

FROM `usertable`,`citytable`<\/p>\n

WHERE usertable.cityid=citytable.cityid\u5728FROM\u5b50\u53e5\u4e2d\u53ef\u7528\u4ee5\u4e0b\u4e24\u79cd\u683c\u5f0f\u4e3a\u8868\u6216\u89c6\u56fe\u6307\u5b9a\u522b\u540d\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:\u8868\u540d as \u522b\u540d<\/p>\n

\u8868\u540d \u522b\u540d\u4f8b\u5982\u4e0a\u9762\u8bed\u53e5\u53ef\u7528\u8868\u7684\u522b\u540d\u683c\u5f0f\u8868\u793a\u4e3a\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT `username`,b.cityid<\/p>\n

FROM usertable a,citytable b<\/p>\n

WHERE a.cityid=b.cityidSELECT\u4e0d\u4ec5\u80fd\u4ece\u8868\u6216\u89c6\u56fe\u4e2d\u68c0\u7d22\u6570\u636e\uff0c\u5b83\u8fd8\u80fd\u591f\u4ece\u5176\u5b83\u67e5\u8be2\u8bed\u53e5\u6240\u8fd4\u56de\u7684\u7ed3\u679c\u96c6\u5408\u4e2d\u67e5\u8be2\u6570\u636e\u3002<\/p>\n

\u4f8b\u5982\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT a.au_fname+a.au_lname<\/p>\n

FROM authors a,titleauthor ta<\/p>\n

(SELECT `title_id`,`title`<\/p>\n

FROM `titles`<\/p>\n

WHERE ` ytd_sales`>10000<\/p>\n

) AS t<\/p>\n

WHERE a.au_id=ta.au_id<\/p>\n

AND ta.title_id=t.title_id\u6b64\u4f8b\u4e2d\uff0c\u5c06SELECT\u8fd4\u56de\u7684\u7ed3\u679c\u96c6\u5408\u7ed9\u4e88\u4e00\u522b\u540dt\uff0c\u7136\u540e\u518d\u4ece\u4e2d\u68c0\u7d22\u6570\u636e\u3002<\/p>\n

(\u4e09) \u4f7f\u7528WHERE\u5b50\u53e5\u8bbe\u7f6e\u67e5\u8be2\u6761\u4ef6<\/p>\n

WHERE\u5b50\u53e5\u8bbe\u7f6e\u67e5\u8be2\u6761\u4ef6\uff0c\u8fc7\u6ee4\u6389\u4e0d\u9700\u8981\u7684\u6570\u636e\u884c\u3002\u4f8b\u5982\u4e0b\u9762\u8bed\u53e5\u67e5\u8be2\u5e74\u9f84\u5927\u4e8e20\u7684\u6570\u636e\uff1a<\/p>\n

\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT * FROM usertable WHERE age>20 WHERE\u5b50\u53e5\u53ef\u5305\u62ec\u5404\u79cd\u6761\u4ef6\u8fd0\u7b97\u7b26\uff1a<\/p>\n

\u6bd4\u8f83\u8fd0\u7b97\u7b26(\u5927\u5c0f\u6bd4\u8f83)\uff1a>\u3001>=\u3001=\u3001\u3001!>\u3001!=10 AND age\u590d\u5236\u5185\u5bb9\u5230\u526a\u8d34\u677f<\/p>\n

\u4ee3\u7801:SELECT * FROM `usertable` ORDER BY `age` DESC,`userid`<\/p>\n

ASC\u53e6\u5916\uff0c\u53ef\u4ee5\u6839\u636e\u8868\u8fbe\u5f0f\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n

\u8003\u65e0\u5fe7\u5c0f\u7f16\u63a8\u8350\uff1a<\/p>\n

\u66f4\u591a\u8ba1\u7b97\u673a\u7b49\u7ea7\u8003\u8bd5\u771f\u9898\u53ca\u7b54\u6848>>>\u70b9\u51fb\u67e5\u770b<\/p>\n

\u60f3\u77e5\u9053\u66f4\u591a\u5173\u4e8e\u8ba1\u7b97\u673a\u7b49\u7ea7\u62a5\u8003\u6307\u5357\u3001\u8003\u8bd5\u65f6\u95f4\u548c\u8003\u8bd5\u4fe1\u606f\u7684\u6700\u65b0\u8d44\u8baf\u5728\u8fd9\u91cc>>><\/p>\n

\u672c\u6587\u7f51\u5740\uff1ahttp:\/\/www.k51.com.cn\/info\/jsjdjks\/1801\/3125751.html<\/p>\n

\"mysql\u67e5\u8be2\u8bed\u53e5\u8be6\u89e3_mysql\u57fa\u672c\u8bed\u53e5<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"mysql\u67e5\u8be2\u8bed\u53e5\u8be6\u89e3_mysql\u57fa\u672c\u8bed\u53e5\u95ee\uff1aMySQL\u4e2d\u7b80\u5355\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5199\uff1f\u8003\u65e0\u5fe7\u5c0f\u7f16\u89e3\u7b54\uff1a\u7b80\u5355\u67e5\u8be2\u7b80\u5355\u7684Transact-SQL\u67e5\u8be2\u53ea\u5305\u62ec\u9009...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5156"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5156"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5156\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}