
{"id":2353,"date":"2020-10-12T13:50:12","date_gmt":"2020-10-12T05:50:12","guid":{"rendered":"http:\/\/admin.evshou.com\/?p=2353"},"modified":"2020-10-15T15:42:37","modified_gmt":"2020-10-15T07:42:37","slug":"2020javaweb%e6%95%99%e7%a8%8b%e4%b9%8bmysql%e7%ba%a6%e6%9d%9f%e5%92%8c%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2353","title":{"rendered":"2020Javaweb\u6559\u7a0b\u4e4bMySQL\u7ea6\u675f\u548c\u591a\u8868\u67e5\u8be2"},"content":{"rendered":"<h3>2020Javaweb\u6559\u7a0b\u4e4bMySQL\u7ea6\u675f\u548c\u591a\u8868\u67e5\u8be2<\/h3>\n<p><strong><span style=\"color: #ff0000;\">\u7b2c\u4e00\u8282 \u6570\u636e\u5b8c\u6574\u6027<\/span><\/strong><\/p>\n<p>\u4f5c\u7528\uff1a\u4fdd\u8bc1\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u4e2d\u662f\u6b63\u786e\u7684\u3002<br \/>\n\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027 = \u5728\u521b\u5efa\u8868\u65f6\u7ed9\u8868\u4e2d\u6dfb\u52a0\u7ea6\u675f<\/p>\n<p><span style=\"color: #ff0000;\">\u5b8c\u6574\u6027\u7684\u5206\u7c7b<\/span>\uff1a<br \/>\n\u5b9e\u4f53\u5b8c\u6574\u6027: \u884c<br \/>\n\u57df\u5b8c\u6574\u6027: \u5217<br \/>\n\u5f15\u7528\u5b8c\u6574\u6027: \u5b66\u751f\u8868(\u5b66\u53f7 ,\u59d3\u540d) \u6210\u7ee9\u8868( \u5b66\u53f7,\u79d1\u76ee,\u6210\u7ee9) \u79d1\u76ee\u8868\uff08\u79d1\u76ee\u7f16\u53f7\uff0c\u79d1\u76ee\u540d\u79f0\uff09<!--more--><\/p>\n<p>1.1 <span style=\"color: #ff0000;\">\u5b9e\u4f53\u5b8c\u6574\u6027\u7ea6\u675f<\/span><\/p>\n<p>\u5b9e\u4f53\uff1a\u5373\u8868\u4e2d\u7684\u4e00\u884c(\u4e00\u6761\u8bb0\u5f55)\u4ee3\u8868\u4e00\u4e2a\u5b9e\u4f53\uff08entity\uff09<\/p>\n<p>\u5b9e\u4f53\u5b8c\u6574\u6027\u7684\u4f5c\u7528\uff1a\u6807\u8bc6\u6bcf\u4e00\u884c\u6570\u636e\u4e0d\u91cd\u590d\u3002 \u5b9e\u4f53\u552f\u4e00<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u7ea6\u675f\u7c7b\u578b<\/span><\/strong>\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">\u4e3b\u952e\u7ea6\u675f<\/span>\uff08primary key\uff09<\/p>\n<p><span style=\"color: #ff0000;\">\u552f\u4e00\u7ea6\u675f<\/span>(unique)<\/p>\n<p><span style=\"color: #ff0000;\">\u81ea\u52a8\u589e\u957f\u5217<\/span>(auto_increment)<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u4e3b\u952e\u7ea6\u675f\uff08primary key\uff09<\/span><\/strong><\/p>\n<p>\u200b \u6ce8\uff1a\u6bcf\u4e2a\u8868\u4e2d\u8981\u6709\u4e00\u4e2a\u4e3b\u952e\u3002<\/p>\n<p>\u200b \u7279\u70b9\uff1a\u6570\u636e\u552f\u4e00\uff0c\u4e14\u4e0d\u80fd\u4e3anull<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u552f\u4e00\u7ea6\u675f(unique)<\/span><\/strong><\/p>\n<p>\u7279\u70b9\uff1a\u6570\u636e\u4e0d\u80fd\u91cd\u590d\u3002\u53ef\u4ee5\u4e3anull<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u81ea\u52a8\u589e\u957f\u5217(auto_increment)<\/span><\/strong><\/p>\n<p><span style=\"color: #008000;\">sqlserver\u6570\u636e\u5e93 (identity) oracle\u6570\u636e\u5e93( sequence)<\/span><\/p>\n<p><span style=\"color: #008000;\">\u81ea\u52a8\u589e\u957f\u4e0d\u80fd\u5355\u72ec\u4f7f\u7528\uff0c\u4e00\u822c\u9700\u8981\u548c\u4e3b\u952e\u914d\u5408\u3002<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u7ed9\u4e3b\u952e\u6dfb\u52a0\u81ea\u52a8\u589e\u957f\u7684\u6570\u503c\uff0c\u5217\u53ea\u80fd\u662f\u6570\u503c\u7c7b\u578b<\/span><\/p>\n<p>CREATE TABLE users(<br \/>\nid INT <span style=\"color: #ff0000;\">AUTO_INCREMENT PRIMARY KEY,#\u81ea\u52a8\u589e\u957f\u4e14\u4e3b\u952e<\/span><br \/>\nusername VARCHAR(20) NOT NULL,<br \/>\nidentity VARCHAR(18) <span style=\"color: #ff0000;\">UNIQUE NOT NULL,#\u552f\u4e00\u7ea6\u675f\u4e0d\u53ef\u91cd\u590d<\/span><br \/>\nmobile VARCHAR(11) NOT NULL<br \/>\n)CHARSET=utf8<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u57df\u5b8c\u6574\u6027\u7ea6\u675f<br \/>\n<\/strong><\/span><\/p>\n<p>\u57df\u5b8c\u6574\u6027\u7ea6\u675f\u7684\u4f5c\u7528\uff1a\u9650\u5236\u6b64\u5355\u5143\u683c\u7684\u6570\u636e\u6b63\u786e\uff0c\u4e0d\u5bf9\u5176\u5b83\u5355\u5143\u683c\u8d77\u4f5c\u7528\uff0c\u57df\u4ee3\u8868\u5f53\u524d\u5355\u5143\u683c.<br \/>\n\u57df\u5b8c\u6574\u6027\u7ea6\u675f\uff1a\u6570\u636e\u7c7b\u578b\u3001\u975e\u7a7a\u7ea6\u675f\uff08not null\uff09\u3001\u9ed8\u8ba4\u503c\u7ea6\u675f(default)<br \/>\ncheck\u7ea6\u675f\uff08mysql\u4e0d\u652f\u6301\uff09check(sex=&#8217;\u7537&#8217;or sex=&#8217;\u5973&#8217;)<\/p>\n<p>CREATE TABLE users(<br \/>\nusername VARCHAR(20)<span style=\"color: #ff0000;\"> NOT NULL,#\u975e\u7a7a\u7ea6\u675f<\/span><br \/>\nsex VARCHAR(2) <span style=\"color: #ff0000;\">DEFAULT &#8216;\u7537&#8217;#\u9ed8\u8ba4\u503c\u7ea6\u675f<\/span><br \/>\n)CHARSET=utf8<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u5f15\u7528\u5b8c\u6574\u6027\u7ea6\u675f<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">\u5916\u952e\u7ea6\u675f\uff1aFOREIGN KEY<\/span><\/p>\n<p><strong><span style=\"color: #ff0000;\">\u5916\u952e\u5217\u7684\u6570\u636e\u7c7b\u578b\u4e00\u5b9a\u8981\u4e0e\u4e3b\u952e\u7684\u7c7b\u578b\u4e00\u81f4<\/span><\/strong><\/p>\n<p>CREATE TABLE stu(#\u5b66\u751f\u8868<br \/>\n<span style=\"color: #ff0000;\">sid INT PRIMARY KEY AUTO_INCREMENT,<\/span><br \/>\nsname VARCHAR(5) NOT NULL,<br \/>\nsex VARCHAR(2) DEFAULT &#8216;\u7537&#8217;<br \/>\n)CHARSET=utf8;<\/p>\n<p>CREATE TABLE score(#\u5b66\u751f\u6210\u7ee9\u8868<br \/>\nid INT PRIMARY KEY AUTO_INCREMENT,<br \/>\nscore DOUBLE(5,2) NOT NULL,<br \/>\n<span style=\"color: #ff0000;\">CONSTRAINT fk_score_sid FOREIGN KEY(id) REFERENCES stu(sid)<\/span><br \/>\n)<\/p>\n<p>INSERT INTO stu(sname,sex)VALUES(&#8216;\u5f20\u4e09&#8217;,&#8217;\u5973&#8217;)#\u6dfb\u52a0\u5b66\u751f<br \/>\nINSERT INTO score(score)VALUES(120.55)#\u6dfb\u52a0\u6210\u7ee9<\/p>\n<p>SELECT*FROM stu<br \/>\nSELECT*FROM score<\/p>\n<hr \/>\n<p><strong><span style=\"color: #ff0000;\">\u591a\u8868\u67e5\u8be2<\/span><\/strong><\/p>\n<p>\u591a\u8868\u7ea6\u675f\uff1a\u5916\u952e\u7ea6\u675f\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u591a\u8868\u7684\u5173\u7cfb<\/span><\/p>\n<p>\u4e00\u5bf9\u591a\u5173\u7cfb\uff1a\u5ba2\u6237\u548c\u8ba2\u5355\uff0c\u5206\u7c7b\u548c\u5546\u54c1\uff0c\u90e8\u95e8\u548c\u5458\u5de5<br \/>\n\u4e00\u5bf9\u591a\u5efa\u8868\u539f\u5219\uff1a\u5728\u591a\u7684\u4e00\u65b9\u521b\u5efa\u4e00\u4e2a\u5b57\u6bb5\uff0c\u5b57\u6bb5\u4f5c\u4e3a\u5916\u952e\u6307\u5411\u4e00\u65b9\u7684\u4e3b\u952e.<\/p>\n<p><span style=\"color: #ff0000;\">\u591a\u5bf9\u591a\u5173\u7cfb<\/span><\/p>\n<p>\u5b66\u751f\u548c\u8bfe\u7a0b:<\/p>\n<p>\u591a\u5bf9\u591a\u5173\u7cfb\u5efa\u8868\u539f\u5219\uff1a\u9700\u8981\u521b\u5efa\u7b2c\u4e09\u5f20\u8868,\u4e2d\u95f4\u8868\u4e2d\u81f3\u5c11\u4e24\u4e2a\u5b57\u6bb5\uff0c\u8fd9\u4e24\u4e2a\u5b57\u6bb5\u5206\u522b\u4f5c\u4e3a\u5916\u952e\u6307\u5411\u5404\u81ea\u4e00\u65b9\u7684\u4e3b\u952e.<\/p>\n<p><span style=\"color: #ff0000;\">\u4e00\u5bf9\u4e00\u5173\u7cfb<\/span><\/p>\n<p>\u4e00\u4e2a\u4e08\u592b\u5bf9\u5e94\u4e00\u4e2a\u59bb\u5b50<\/p>\n<p>\u4e00\u4e2a\u5458\u5de5\u5bf9\u5e94\u4e00\u4e2a\u7b80\u5386<\/p>\n<p>\u5728\u5b9e\u9645\u7684\u5f00\u53d1\u4e2d\u5e94\u7528\u4e0d\u591a.\u56e0\u4e3a\u4e00\u5bf9\u4e00\u53ef\u4ee5\u521b\u5efa\u6210\u4e00\u5f20\u8868.<\/p>\n<p><span style=\"color: #ff0000;\">\u4e24\u79cd\u5efa\u8868\u539f\u5219<\/span>\uff1a<\/p>\n<p>\u552f\u4e00\u5916\u952e\u5bf9\u5e94\uff1a\u5728\u591a\u7684\u4e00\u65b9\u521b\u5efa\u4e00\u4e2a\u5916\u952e\u6307\u5411\u4e00\u7684\u4e00\u65b9\u7684\u4e3b\u952e\uff0c\u5c06\u5916\u952e\u8bbe\u7f6e\u4e3aunique\u548c\u975e\u7a7a.<\/p>\n<p>\u4e3b\u952e\u5bf9\u5e94\uff1a\u8ba9\u4e00\u5bf9\u4e00\u7684\u53cc\u65b9\u7684\u4e3b\u952e\u8fdb\u884c\u5efa\u7acb\u5173\u7cfb. \u552f\u4e00 \u975e\u7a7a<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u591a\u8868\u67e5\u8be2<\/span><\/strong><\/p>\n<p>\u591a\u8868\u67e5\u8be2\u6709\u5982\u4e0b\u51e0\u79cd\uff1a<\/p>\n<p>1 \u5408\u5e76\u7ed3\u679c\u96c6\uff1bUNION \u3001 UNION ALL<\/p>\n<p>2 \u8fde\u63a5\u67e5\u8be2<\/p>\n<p>\u5185\u8fde\u63a5 INNER JOIN ON<\/p>\n<p>\u5916\u8fde\u63a5 OUTER JOIN ON<\/p>\n<p>\u5de6\u5916\u8fde\u63a5 LEFT OUTER JOIN<br \/>\n\u53f3\u5916\u8fde\u63a5 RIGHT OUTER JOIN<\/p>\n<p><span style=\"color: #ff0000;\">\u5b50\u67e5\u8be2<\/span><\/p>\n<p>2.2.1 \u5408\u5e76\u7ed3\u679c\u96c6<\/p>\n<p>\u4f5c\u7528\uff1a\u5408\u5e76\u7ed3\u679c\u96c6\u5c31\u662f\u628a\u4e24\u4e2aselect\u8bed\u53e5\u7684\u67e5\u8be2\u7ed3\u679c\u5408\u5e76\u5230\u4e00\u8d77\uff01<\/p>\n<p><span style=\"color: #ff0000;\">\u6ce8\u610f\uff1a\u88ab\u5408\u5e76\u7684\u4e24\u4e2a\u7ed3\u679c\uff1a\u5217\u6570\u5fc5\u987b\u76f8\u540c\uff0c\u5217\u7c7b\u578b\u53ef\u4ee5\u4e0d\u540c\u3002<\/span><\/p>\n<p>\u5408\u5e76\u7ed3\u679c\u96c6\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<p>UNION\uff1a\u53bb\u9664\u91cd\u590d\u8bb0\u5f55\uff0c\u4f8b\u5982\uff1aSELECT*FROM emp UNION SELECT*FROM empno<\/p>\n<p>UNION ALL\uff1a\u4e0d\u53bb\u9664\u91cd\u590d\u8bb0\u5f55\uff0c\u4f8b\u5982\uff1aSELECT*FROM emp UNION ALL SELECT*FROM empno<\/p>\n<p><span style=\"color: #ff0000;\">\u8fde\u63a5\u67e5\u8be2<\/span><\/p>\n<p>\u8fde\u63a5\u67e5\u8be2\u5c31\u662f\u6c42\u51fa\u591a\u4e2a\u8868\u7684\u4e58\u79ef\uff0c\u4f8b\u5982t1\u8fde\u63a5t2\uff0c\u90a3\u4e48\u67e5\u8be2\u51fa\u7684\u7ed3\u679c\u5c31\u662ft1*t2\u3002<\/p>\n<p>\u8fde\u63a5\u67e5\u8be2\u4f1a\u4ea7\u751f<span style=\"color: #ff0000;\">\u7b1b\u5361\u5c14\u79ef<\/span>\uff0c\u5047\u8bbe\u96c6\u5408A={a,b}\uff0c\u96c6\u5408B={0,1,2}\uff0c\u5219\u4e24\u4e2a\u96c6\u5408\u7684\u7b1b\u5361\u5c14\u79ef\u4e3a{(a,0),(a,1),(a,2),(b,0),(b,1),(b,2)}\u3002\u53ef\u4ee5\u6269\u5c55\u5230\u591a\u4e2a\u96c6\u5408\u7684\u60c5\u51b5\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u5b9e\u4f8b<\/span>\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">emp\u8868<\/span><\/p>\n<p>CREATE TABLE emp(<br \/>\nid INT AUTO_INCREMENT PRIMARY KEY,<br \/>\nename VARCHAR(20) NOT NULL,<br \/>\nsex VARCHAR(2) NOT NULL,<br \/>\nidentity VARCHAR(18) UNIQUE NOT NULL<br \/>\n)CHARSET=utf8<\/p>\n<p><span style=\"color: #ff0000;\">dept\u8868<\/span><\/p>\n<p>CREATE TABLE dept(<br \/>\ndeptno INT,<br \/>\ndname VARCHAR(20),<br \/>\nloc VARCHAR(5)<br \/>\n)CHARSET=utf8<\/p>\n<p>\u6267\u884csql\u8bed\u53e5\uff1a<span style=\"color: #ff0000;\">SELECT*FROM emp,dept<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u4f7f\u7528\u4e3b\u5916\u952e\u5173\u7cfb\u505a\u4e3a\u6761\u4ef6\u6765\u53bb\u9664\u65e0\u7528\u4fe1\u606f<\/span><br \/>\nSELECT*FROM emp,dept WHERE emp.`depno`=dept.`deptno`<\/p>\n<p><span style=\"color: #ff0000;\">\u5982\u679c\u4e0d\u9700\u8981\u90a3\u4e48\u591a\u5217\uff0c\u53ef\u4ee5\u7b5b\u9009\u6307\u5b9a\u5217<\/span><br \/>\nSELECT emp.`id`,emp.`ename`,emp.`salary`,dept.`dname` FROM emp,dept WHERE emp.`depno`=dept.`deptno`<\/p>\n<p><span style=\"color: #ff0000;\">\u5185\u8fde\u63a5<br \/>\n<\/span><\/p>\n<p>\u4e0a\u9762\u8fde\u63a5\u8bed\u53e5\u5c31\u662f\u5185\u8fde\u63a5\uff0c\u4f46\u4e0d\u662fSQL\u6807\u51c6\u4e2d\u7684\u67e5\u8be2\u65b9\u5f0f\uff0c\u662fmysql\u6269\u5c55\u7684\u529f\u80fd<\/p>\n<p>SQL\u6807\u51c6\u7684\u5185\u8fde\u63a5\u4e3a\uff1a<br \/>\n<span style=\"color: #ff0000;\">SELECT*FROM emp INNER JOIN dept ON emp.`depno`=dept.`deptno`<br \/>\n\u6ce8\u610f\uff1aon\u540e\u9762 \u4e3b\u5916\u952e\u5173\u7cfb<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u5916\u8fde\u63a5<\/span><\/p>\n<p>\u5305\u62ec\u5de6\u5916\u8fde\u63a5\u548c\u53f3\u5916\u8fde\u63a5\uff0c\u5916\u8fde\u63a5\u7684\u7279\u70b9\uff1a\u67e5\u8be2\u51fa\u7684\u7ed3\u679c\u5b58\u5728\u4e0d\u6ee1\u8db3\u6761\u4ef6\u7684\u53ef\u80fd\u3002<\/p>\n<p><span style=\"color: #ff0000;\">a.\u5de6\u5916\u8fde\u63a5\uff1a\u4ee5\u5de6\u8868\u4e3a\u4e3b\u8868\uff0c\u53f3\u8868\u662f\u4ece\u8868<\/span><\/p>\n<p><span style=\"color: #ff0000;\">SELECT*FROM emp LEFT JOIN dept ON emp.`depno`=dept.`deptno`<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u5de6\u8fde\u63a5\u662f\u5148\u67e5\u8be2\u51fa\u5de6\u8868\uff08\u5373\u4ee5\u5de6\u8868\u4e3a\u4e3b\uff09\uff0c\u7136\u540e\u67e5\u8be2\u53f3\u8868\uff0c\u5de6\u8868\u4e2d\u6ee1\u8db3\u6761\u4ef6\u548c\u4e0d\u6ee1\u8db3\u6761\u4ef6\u90fd\u663e\u793a\u51fa\u6765\uff0c\u53f3\u8fb9\u4e0d\u6ee1\u8db3\u6761\u4ef6\u7684\u663e\u793aNULL\u3002<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u5916\u8fde\u63a5<\/span><\/p>\n<p>\u53f3\u8fde\u63a5\u5c31\u662f\u5148\u628a\u53f3\u8868\u4e2d\u6240\u6709\u8bb0\u5f55\u90fd\u67e5\u8be2\u51fa\u6765\uff0c\u7136\u540e\u5de6\u8868\u6ee1\u8db3\u6761\u4ef6\u7684\u663e\u793a\uff0c\u4e0d\u6ee1\u8db3\u663e\u793aNULL\u3002\u4f8b\u5982\u5728dept\u8868\u4e2d\u768440\u90e8\u95e8\u5e76\u4e0d\u5b58\u5728\u5458\u5de5\uff0c\u4f46\u5728\u53f3\u8fde\u63a5\u4e2d\uff0c\u5982\u679cdept\u8868\u4e3a\u53f3\u8868\uff0c\u90a3\u4e48\u8fd8\u662f\u4f1a\u67e5\u51fa40\u90e8\u95e8\uff0c\u4f46\u76f8\u5e94\u7684\u5458\u5de5\u4fe1\u606f\u4e3aNULL\u3002<\/p>\n<p>SELECT*FROM emp RIGHT OUTER JOIN dept ON emp.`depno`=dept.`deptno`<\/p>\n<p><span style=\"color: #ff0000;\">\u8fde\u63a5\u67e5\u8be2\u603b\u7ed3<\/span>\uff1a<\/p>\n<p>\u200b \u8fde\u63a5\u4e0d\u9650\u4e8e\u4e24\u5f20\u8868\uff0c\u8fde\u63a5\u67e5\u8be2\u4e5f\u53ef\u4ee5\u662f\u4e09\u5f20\u3001\u56db\u5f20\uff0c\u751a\u81f3N\u5f20\u8868\u7684\u8fde\u63a5\u67e5\u8be2\u3002\u901a\u5e38\u8fde\u63a5\u67e5\u8be2\u4e0d\u53ef\u80fd\u9700\u8981\u6574\u4e2a\u7b1b\u5361\u5c14\u79ef\uff0c\u800c\u53ea\u662f\u9700\u8981\u5176\u4e2d\u4e00\u90e8\u5206\uff0c\u90a3\u4e48\u8fd9\u65f6\u5c31\u9700\u8981\u4f7f\u7528\u6761\u4ef6\u6765\u53bb\u9664\u4e0d\u9700\u8981\u7684\u8bb0\u5f55\u3002\u8fd9\u4e2a\u6761\u4ef6\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u90fd\u662f\u4f7f\u7528\u4e3b\u5916\u952e\u5173\u7cfb\u53bb\u9664\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u5b50\u67e5\u8be2<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u4e00\u4e2aselect\u8bed\u53e5\u4e2d\u5305\u542b\u53e6\u4e00\u4e2a\u5b8c\u6574\u7684select\u8bed\u53e5<\/span>\u3002<\/p>\n<p>\u5b50\u67e5\u8be2\u5c31\u662f\u5d4c\u5957\u67e5\u8be2\uff0c\u5373SELECT\u4e2d\u5305\u542bSELECT\uff0c\u5982\u679c\u4e00\u6761\u8bed\u53e5\u4e2d\u5b58\u5728\u4e24\u4e2a\uff0c\u6216\u4e24\u4e2a\u4ee5\u4e0aSELECT\uff0c\u90a3\u4e48\u5c31\u662f\u5b50\u67e5\u8be2\u8bed\u53e5\u4e86\u3002\u91cc\u9762\u7684\u67e5\u8be2\u53eb\u505a\u5b50\u67e5\u8be2\uff0c\u5916\u5c42\u7684\u67e5\u8be2\u53eb\u7236\u67e5\u8be2\uff0c\u4e00\u822c\u60c5\u51b5\u90fd\u662f\u5148\u6267\u884c\u5b50\u67e5\u8be2\uff0c\u518d\u6267\u884c\u7236\u67e5\u8be2\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u5b50\u67e5\u8be2\u51fa\u73b0\u7684\u4f4d\u7f6e<\/span>\uff1a<\/p>\n<p>\u200bwhere\u540e\uff0c\u4f5c\u4e3a\u88ab\u67e5\u8be2\u7684\u6761\u4ef6\u7684\u4e00\u90e8\u5206\uff1b<\/p>\n<p>from\u540e\uff0c\u4f5c\u4e34\u65f6\u8868\uff1b<\/p>\n<p><span style=\"color: #ff0000;\">\u5f53\u5b50\u67e5\u8be2\u51fa\u73b0\u5728where\u540e\u4f5c\u4e3a\u6761\u4ef6\u65f6\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u5173\u952e\u5b57<\/span>\uff1a<\/p>\n<p>any \u8ddf\u7ed3\u679c\u96c6\u91cc\u9762\u7684\u591a\u884c\u5355\u5217\u90e8\u5206\u8fdb\u884c\u6bd4\u8f83\uff0c\u6ee1\u8db3\u5c31\u8fd4\u56detrue<\/p>\n<p>all \u8ddf\u7ed3\u679c\u91cc\u9762\u7684\u591a\u884c\u5355\u5217\u6240\u6709\u8fdb\u884c\u6bd4\u8f83,\u6240\u6709\u90fd\u6ee1\u8db3\u4e86\u624d\u8fd4\u56detrue<\/p>\n<p><span style=\"color: #ff0000;\">\u5b50\u67e5\u8be2\u7ed3\u679c\u96c6\u7684\u5e38\u89c1\u5f62\u5f0f<\/span>\uff1a<\/p>\n<p>\u5355\u884c\u5355\u5217\uff08\u7528\u4e8e\u6761\u4ef6\uff09<\/p>\n<p>\u591a\u884c\u5355\u5217\uff08\u7528\u4e8e\u6761\u4ef6\uff09<\/p>\n<p>\u591a\u884c\u591a\u5217\uff08\u7528\u4e8e\u8868\uff09<\/p>\n<p>&nbsp;<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<p>1. <span style=\"color: #ff0000;\">\u5de5\u8d44\u9ad8\u4e8eJONES\u7684\u5458\u5de5\u3002<\/span><\/p>\n<p>\u5206\u6790\uff1a<\/p>\n<p>\u67e5\u8be2\u6761\u4ef6\uff1a\u5de5\u8d44&gt;JONES\u5de5\u8d44\uff0c\u5176\u4e2dJONES\u5de5\u8d44\u9700\u8981\u4e00\u6761\u5b50\u67e5\u8be2\u3002<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u67e5\u8be2JONES\u7684\u5de5\u8d44<\/p>\n<p>SELECT sal FROM emp WHERE ename=&#8217;JONES&#8217;;<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u67e5\u8be2\u9ad8\u4e8eJONES\u5de5\u8d44\u7684\u5458\u5de5<\/p>\n<p>SELECT * FROM emp WHERE sal &gt; (\u7b2c\u4e00\u6b65\u7ed3\u679c);<\/p>\n<p>\u7ed3\u679c\uff1a<\/p>\n<p>SELECT * FROM emp WHERE sal &gt; (SELECT sal FROM emp WHERE ename=&#8217;JONES&#8217;);<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">\u67e5\u8be2\u4e0e admin777\u540c\u4e00\u4e2a\u90e8\u95e8\u7684\u5458\u5de5<\/span><\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u67e5\u8be2admin777\u7684\u90e8\u95e8\u7f16\u53f7<br \/>\nSELECT depno FROM emp WHERE ename=&#8217;admin777&#8242;<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u67e5\u8be2\u90e8\u95e8\u7f16\u53f7\u7b49\u4e8eadmin777\u7684\u90e8\u95e8\u7f16\u53f7\u7684\u5458\u5de5<\/p>\n<p>SELECT * FROM emp WHERE depno=<br \/>\n(SELECT depno FROM emp WHERE ename=&#8217;admin777&#8242;)<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">\u5de5\u8d44\u5c0f\u4e8e10\u53f7\u90e8\u95e8\u7684\u6240\u6709\u5458\u5de5\u4fe1\u606f<\/span><\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u67e5\u8be210\u53f7\u90e8\u95e8\u6240\u6709\u5458\u5de5\u5de5\u8d44\uff1a<br \/>\nselect salary from emp where deptno=10<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u67e5\u8be2\u5c0f\u4e8e10\u53f7\u90e8\u95e8\u6240\u6709\u4eba\u5de5\u8d44\u7684\u5458\u5de5\u4fe1\u606f<br \/>\nselect*from emp where salary &lt;all(\u7b2c\u4e00\u6b65)<\/p>\n<p>\u7ed3\u679c\uff1aSELECT * FROM emp WHERE salary&lt;ALL<br \/>\n(SELECT MAX(salary) FROM emp WHERE depno=10)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020Javaweb\u6559\u7a0b\u4e4bMySQL\u7ea6\u675f\u548c\u591a\u8868\u67e5\u8be2 \u7b2c\u4e00\u8282 \u6570\u636e\u5b8c\u6574\u6027 \u4f5c\u7528\uff1a\u4fdd\u8bc1\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u4fdd\u5b58\u5230\u6570\u636e\u5e93 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2353","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2353"}],"version-history":[{"count":1,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2353\/revisions"}],"predecessor-version":[{"id":2354,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2353\/revisions\/2354"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}