{"id":5954,"date":"2019-02-15T11:37:51","date_gmt":"2019-02-15T03:37:51","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=5954"},"modified":"2019-02-15T15:15:44","modified_gmt":"2019-02-15T07:15:44","slug":"mysql%e9%9b%86%e5%90%88%e9%99%a4%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=5954","title":{"rendered":"MYSQL\u96c6\u5408\u9664\u6cd5"},"content":{"rendered":"\n<p> \u96c6\u5408\u9664\u6cd5 \uff0c\u4ee5\u4e0b\u662fSC\u6570\u636e\u8868\uff0c\u539f\u9898\uff1a\u68c0\u7d22\u9009\u4fee\u8bfe\u7a0b\u5305\u62ec\u201c1042\u201d\u5b66\u751f\u6240\u5b66\u7684\u8bfe\u7a0b\u7684\u5b66\u751f\u5b66\u53f7\u3002\u3010\u4e5f\u5c31\u662f\u8bf4\uff1a1042\u5b66\u751f\u9009\u4fee\u4e861\u548c2\uff0c\u67e5\u627e\u8fd8\u6709\u54ea\u4e9b\u5b66\u751f\u9009\u4fee\u7684\u8bfe\u7a0b\u4e2d\u540c\u65f6\u5305\u542b1\u548c2\u3002\u3011<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u5173\u7cfb\u4ee3\u6570\u8868\u8fbe\u5f0f\uff1a<br><\/p>\n\n\n\n<p>    <font size=\"5\">\n\u03c0<sub>Sno,Cno<\/sub>(SC)\u00f7\u03c0<sub>Cno<\/sub>(\u03c3<sub>Sno=1042<\/sub>(SC))\n<\/font> \n<\/p>\n\n\n\n<p>\u4e0b\u9762\u662fmysql\u7684\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><font color=\"#4F81bd\"><strong>select distinct<\/strong><\/font> sno <font color=\"#4F81bd\"><strong>from<\/strong><\/font> SC as s1 <font color=\"#4F81bd\"><strong>where not exists<\/strong><\/font>(\n<font color=\"#4F81bd\"><strong>select<\/strong><\/font> cno <font color=\"#4F81bd\"><strong>from<\/strong><\/font> SC s2 <font color=\"#4F81bd\"><strong>where<\/strong><\/font> sno=<font color=\"#FF0000\"><strong>1042<\/strong><\/font> <font color=\"#4F81bd\"><strong>and<\/strong><\/font> s2.cno <font color=\"#4F81bd\"><strong>not in<\/strong><\/font> \n(<font color=\"#4F81bd\"><strong>select<\/strong><\/font> cno <font color=\"#4F81bd\"><strong>from<\/strong><\/font> SC s3 <font color=\"#4F81bd\"><strong>where<\/strong><\/font> s1.sno = s3.sno));\n<\/pre>\n\n\n\n<p>\u5bf9\u4e8e\u5b9e\u73b0\u65b9\u6cd5\u7684\u5206\u6790\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>select distinct<\/strong> sno <strong>from<\/strong> SC as s1\uff0c\u9009\u51fa\u5f53\u524d\u5b66\u5458\u7684\u5b66\u53f7<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>select<\/strong> cno <strong>from<\/strong> SC s2 <strong>where<\/strong> sno=<strong>1042<\/strong>\uff0c\u662f\u7528\u4e8e\u627e\u51fa\u5b66\u53f7\u662f1042\u9009\u4fee\u7684\u8bfe\u7a0b\u90fd\u6709\u54ea\u4e9b\u3002<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">(<strong>select<\/strong> cno <strong>from<\/strong> SC s3 <strong>where<\/strong> s1.sno = s3.sno)\uff0c\u662f\u7528\u4e8e\u627e\u51fa\u5f53\u524d\u5b66\u53f7\u6240\u9009\u4fee\u7684\u6240\u6709\u8bfe\u7a0b\u3002<\/pre>\n\n\n\n<p>s2.cno <strong>not in<\/strong>\uff0c\u662f\u8ba91042\u5b66\u5458\u9009\u4fee\u8bfe\u7a0b\u7684\u96c6\u5408\u4e0e\u5f53\u524d\u5b66\u5458\u9009\u4fee\u8bfe\u7a0b\u505a\u5dee\u96c6\u3002\u5982\u679c\u5dee\u96c6\u4e3a\u7a7a\u96c6\uff0c\u8bc1\u660e\u5f53\u524d\u5b66\u5458\u4e5f\u81f3\u5c11\u9009\u4fee\u4e861042\u6240\u9009\u4fee\u7684\u6240\u6709\u8bfe\u7a0b\uff1b\u5982\u679c\u4e0d\u4e3a\u7a7a\u96c6\uff0c\u5219\u8bf4\u660e\u5f53\u524d\u5b66\u5458\u81f3\u5c11\u6ca1\u6709\u9009\u4fee1042\u5458\u9009\u4fee\u7684\u8bfe\u7a0b\u4e2d\u7684\u4e00\u4e2a\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662fSC\u8868\u4e2d\u6570\u636e\uff1a<\/p>\n\n\n\n<p>mysql&gt; select * from SC;<br>\n+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+<br>\n| sno  | cno  | grade |<br>\n+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+<br>\n| 3001 |    1 |    93 |<br>\n| 3001 |    2 |    84 |<br>\n| 3001 |    3 |    84 |<br>\n| 3002 |    2 |    83 |<br>\n| 3002 |    3 |    93 |<br>\n| 1042 |    1 |    84 |<br>\n| 1042 |    2 |    82 |<br>\n+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+<br>\n7 rows in set (0.00 sec)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u96c6\u5408\u9664\u6cd5 \uff0c\u4ee5\u4e0b\u662fSC\u6570\u636e\u8868\uff0c\u539f\u9898\uff1a\u68c0\u7d22\u9009\u4fee\u8bfe\u7a0b\u5305\u62ec\u201c1042\u201d\u5b66\u751f\u6240\u5b66\u7684\u8bfe\u7a0b\u7684\u5b66\u751f\u5b66\u53f7\u3002\u3010\u4e5f\u5c31\u662f\u8bf4\uff1a1042\u5b66\u751f\u9009\u4fee\u4e861\u548c2\uff0c\u67e5\u627e\u8fd8\u6709\u54ea\u4e9b\u5b66\u751f\u9009\u4fee\u7684\u8bfe\u7a0b\u4e2d\u540c\u65f6&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=5954\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-5954","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/5954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5954"}],"version-history":[{"count":7,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/5954\/revisions"}],"predecessor-version":[{"id":6091,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/5954\/revisions\/6091"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}