{"id":7393,"date":"2022-09-30T15:12:24","date_gmt":"2022-09-30T07:12:24","guid":{"rendered":"https:\/\/aif.amtbbs.org\/?p=7393"},"modified":"2022-09-30T15:12:24","modified_gmt":"2022-09-30T07:12:24","slug":"sql%e9%ab%98%e6%95%88%e6%9f%a5%e8%af%a2%e5%bb%ba%e8%ae%ae%ef%bc%8c%e4%bd%a0%e5%ad%a6%e4%bc%9a%e4%ba%86%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/aif.amtbbs.org\/index.php\/2022\/09\/30\/7393\/","title":{"rendered":"SQL\u9ad8\u6548\u67e5\u8be2\u5efa\u8bae\uff0c\u4f60\u5b66\u4f1a\u4e86\u5417\uff1f"},"content":{"rendered":"<p data-id=\"p838747a-mHo1O4St\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7395\" src=\"https:\/\/aiforumimage.oss-cn-shanghai.aliyuncs.com\/wp-content\/uploads\/2022\/09\/3001-1.jpg\" width=\"208\" height=\"116\" alt=\"\" \/><\/p>\n<p data-id=\"p838747a-mHo1O4St\">\u4e3a\u4ec0\u4e48\u522b\u4eba\u7684\u67e5\u8be2\u53ea\u8981\u51e0\u79d2\uff0c\u800c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5c11\u5219\u5341\u591a\u79d2\uff0c\u591a\u5219\u5341\u51e0\u5206\u949f\u751a\u81f3\u51e0\u4e2a\u5c0f\u65f6\uff1f\u4e0e\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u662f\u5426\u9ad8\u6548\u6709\u5f88\u5927\u5173\u7cfb\u3002<\/p>\n<p data-id=\"p838747a-wSrBgKSb\">\u4eca\u5929\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u5199\u51fa\u6bd4\u8f83\u9ad8\u6548\u7684\u67e5\u8be2\u8bed\u53e5\u3002<\/p>\n<h4 id=\"hce1b53f-BGKWOULo\" data-id=\"hce1b53f-BGKWOULo\">1.\u5c3d\u91cf\u4e0d\u8981\u4f7f\u7528NULL\u5f53\u9ed8\u8ba4\u503c<\/h4>\n<p data-id=\"p838747a-EYvs5B4I\">\u5728\u6709\u7d22\u5f15\u7684\u5217\u4e0a\u5982\u679c\u5b58\u5728NULL\u503c\u4f1a\u4f7f\u5f97\u7d22\u5f15\u5931\u6548\uff0c\u964d\u4f4e\u67e5\u8be2\u901f\u5ea6\uff0c\u8be5\u5982\u4f55\u4f18\u5316\u5462\uff1f\u4f8b\u5982\uff1a<\/p>\n<p data-id=\"p838747a-ziEtfuPn\">SELECT * \u00a0FROM [Sales].[Temp_SalesOrder] WHERE UnitPrice IS NULL<\/p>\n<p data-id=\"p838747a-HXl0PoWA\">\u6211\u4eec\u53ef\u4ee5\u5c06NULL\u7684\u503c\u8bbe\u7f6e\u62100\u6216\u5176\u4ed6\u56fa\u5b9a\u6570\u503c\uff0c\u8fd9\u6837\u4fdd\u8bc1\u7d22\u5f15\u80fd\u591f\u7ee7\u7eed\u6709\u6548\u3002<\/p>\n<p data-id=\"p838747a-UujsjJN7\">SELECT * \u00a0FROM [Sales].[Temp_SalesOrder] WHERE UnitPrice =0<\/p>\n<p data-id=\"p838747a-Vu2Cg6gB\">\u8fd9\u662f\u6539\u5199\u540e\u7684\u67e5\u8be2\u8bed\u53e5\uff0c\u6548\u7387\u4f1a\u6bd4\u4e0a\u9762\u7684\u5feb\u5f88\u591a\u3002<\/p>\n<h4 id=\"hce1b53f-m60JTGaM\" data-id=\"hce1b53f-m60JTGaM\">2.\u5c3d\u91cf\u4e0d\u8981\u5728WHERE\u6761\u4ef6\u8bed\u53e5\u4e2d\u4f7f\u7528!=\u6216&lt;&gt;<\/h4>\n<p data-id=\"p838747a-o42WStQV\">\u5728WHERE\u8bed\u53e5\u4e2d\u4f7f\u7528!=\u6216&lt;&gt;\u4e5f\u4f1a\u4f7f\u5f97\u7d22\u5f15\u5931\u6548\uff0c\u8fdb\u800c\u8fdb\u884c\u5168\u8868\u626b\u63cf\uff0c\u8fd9\u6837\u5c31\u4f1a\u82b1\u8d39\u8f83\u957f\u65f6\u95f4\u4e86\u3002<\/p>\n<h4 id=\"hce1b53f-kjRWffmP\" data-id=\"hce1b53f-kjRWffmP\">3.\u5e94\u5c3d\u91cf\u907f\u514d\u5728 WHERE\u5b50\u53e5\u4e2d\u4f7f\u7528 OR<\/h4>\n<p data-id=\"p838747a-u4bC1doU\">\u9047\u5230\u6709OR\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06OR\u4f7f\u7528UNION ALL\u6765\u8fdb\u884c\u6539\u5199<\/p>\n<p data-id=\"p838747a-Aezb8560\">\u4f8b\u5982\uff1a<\/p>\n<p data-id=\"p838747a-GMCAh1vz\">SELECT * FROM T1 WHERE NUM=10 OR NUM=20<\/p>\n<p data-id=\"p838747a-zVRYcFWW\">\u53ef\u4ee5\u6539\u5199\u6210<\/p>\n<p data-id=\"p838747a-vDhG4mDQ\">SELECT * FROM T1 WHERE NUM=10<\/p>\n<p data-id=\"p838747a-roeR4C1h\">UNION ALL<\/p>\n<p data-id=\"p838747a-zl06a1xj\">SELECT * FROM T1 WHERE NUM=20<\/p>\n<h4 id=\"hce1b53f-JCd0nCV2\" data-id=\"hce1b53f-JCd0nCV2\">4.IN\u548cNOT IN\u4e5f\u8981\u614e\u7528<\/h4>\n<p data-id=\"p838747a-yzdmAtso\">\u9047\u5230\u8fde\u7eed\u786e\u5207\u503c\u7684\u65f6\u5019 \uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528BETWEEN AND\u6765\u8fdb\u884c\u4f18\u5316<\/p>\n<p data-id=\"p838747a-KWe8nnyA\">\u4f8b\u5982\uff1a<\/p>\n<p data-id=\"p838747a-9NH1p9pH\">SELECT * FROM T1 WHERE NUM IN (5,6,7,8)<\/p>\n<p data-id=\"p838747a-FMGi4zlh\">\u53ef\u4ee5\u6539\u5199\u6210\uff1a<\/p>\n<p data-id=\"p838747a-YA2SkySH\">SELECT * FROM T1 WHERE NUM BETWEEN 5 AND 8.<\/p>\n<h4 id=\"hce1b53f-kJqOinMS\" data-id=\"hce1b53f-kJqOinMS\">5.\u5b50\u67e5\u8be2\u4e2d\u7684IN\u53ef\u4ee5\u4f7f\u7528EXISTS\u6765\u4ee3\u66ff<\/h4>\n<p data-id=\"p838747a-uT4Ga0FD\">\u5b50\u67e5\u8be2\u4e2d\u7ecf\u5e38\u4f1a\u4f7f\u7528\u5230IN\uff0c\u5982\u679c\u6362\u6210EXISTS\u505a\u5173\u8054\u67e5\u8be2\u4f1a\u66f4\u5feb<\/p>\n<p data-id=\"p838747a-xiQZShOm\">\u4f8b\u5982\uff1a<\/p>\n<p data-id=\"p838747a-BZyTxLah\">SELECT * FROM T1 WHERE ORDER_ID IN (SELECT ORDER_ID FROM ORDER WHERE PRICE&gt;20);<\/p>\n<p data-id=\"p838747a-QmdrOkz6\">\u53ef\u4ee5\u6539\u5199\u6210\uff1a<\/p>\n<p data-id=\"p838747a-HcpeD6pm\">SELECT * FROM T1 AS A WHERE EXISTS (SELECT 1 FROM ORDER \u00a0AS B WHERE A.ORDER_ID=B.ORDER_ID AND B.PRICE&gt;20)<\/p>\n<p data-id=\"p838747a-4Ms8J1X7\">\u867d\u7136\u4ee3\u7801\u91cf\u53ef\u80fd\u6bd4\u4e0a\u9762\u7684\u591a\u4e00\u70b9\uff0c\u4f46\u662f\u5728\u4f7f\u7528\u6548\u679c\u4e0a\u4f1a\u4f18\u4e8e\u4e0a\u9762\u7684\u67e5\u8be2\u8bed\u53e5\u3002<\/p>\n<h4 id=\"hce1b53f-ZkgD493E\" data-id=\"hce1b53f-ZkgD493E\">6.\u6a21\u7cca\u5339\u914d\u5c3d\u91cf\u4f7f\u7528\u524d\u7f00\u5339\u914d<\/h4>\n<p data-id=\"p838747a-hJIyLQjx\">\u5728\u8fdb\u884c\u6a21\u7cca\u67e5\u8be2\uff0c\u4f7f\u7528LIKE\u65f6\u5c3d\u91cf\u4f7f\u7528\u524d\u7f00\u5339\u914d\uff0c\u8fd9\u6837\u4f1a\u8d70\u7d22\u5f15\uff0c\u51cf\u5c11\u67e5\u8be2\u65f6\u95f4\u3002<\/p>\n<p data-id=\"p838747a-LfIZgGaI\">\u4f8b\u5982\uff1a<\/p>\n<p data-id=\"p838747a-lEEAp2fh\">SELECT * FROM T1 WHERE NAME LIKE &#8216;%\u674e\u56db%&#8217;<\/p>\n<p data-id=\"p838747a-3fD5ghs9\">\u6216\u8005<\/p>\n<p data-id=\"p838747a-tGqYAk2Y\">SELECT * FROM T1 WHERE NAME LIKE &#8216;%\u674e\u56db&#8217;<\/p>\n<p data-id=\"p838747a-UNZaKPLI\">\u5747\u4e0d\u4f1a\u8d70\u7d22\u5f15\uff0c\u53ea\u6709\u5f53\u5982\u4e0b\u60c5\u51b5<\/p>\n<p data-id=\"p838747a-farnppD4\">SELECT * FROM T1 WHERE NAME LIKE &#8216;\u674e\u56db%&#8217;\u624d\u4f1a\u8d70\u7d22\u5f15\u3002<\/p>\n<p data-id=\"p838747a-MQEPu7cV\">\u4e0a\u8ff0\u8fd9\u4e9b\u90fd\u662f\u5e73\u5e38\u7ecf\u5e38\u4f1a\u9047\u5230\u7684\uff0c\u5c31\u76f4\u63a5\u544a\u8bc9\u5927\u5bb6\u600e\u4e48\u64cd\u4f5c\u4e86\uff0c\u5177\u4f53\u53ef\u4ee5\u4e0b\u53bb\u505a\u8bd5\u9a8c\u5c1d\u8bd5\u4e00\u4e0b\u3002<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_7393\" class=\"pvc_stats total_only  \" data-element-id=\"7393\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.0\" viewBox=\"0 0 502 315\" preserveAspectRatio=\"xMidYMid meet\"><g transform=\"translate(0,332) scale(0.1,-0.1)\" fill=\"\" stroke=\"none\"><path d=\"M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z\"\/><path d=\"M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z\"\/><path d=\"M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z\"\/><path d=\"M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z\"\/><path d=\"M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z\"\/><path d=\"M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z\"\/><path d=\"M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z\"\/><path d=\"M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z\"\/><path d=\"M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z\"\/><\/g><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/aif.amtbbs.org\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u522b\u4eba\u7684\u67e5\u8be2\u53ea\u8981\u51e0\u79d2\uff0c\u800c\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u5c11\u5219\u5341\u591a\u79d2\uff0c\u591a\u5219\u5341\u51e0\u5206\u949f\u751a\u81f3\u51e0\u4e2a\u5c0f\u65f6\uff1f\u4e0e\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u662f\u5426\u9ad8\u6548\u6709\u5f88\u5927\u5173\u7cfb [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_7393\" class=\"pvc_stats total_only  \" data-element-id=\"7393\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.0\" viewBox=\"0 0 502 315\" preserveAspectRatio=\"xMidYMid meet\"><g transform=\"translate(0,332) scale(0.1,-0.1)\" fill=\"\" stroke=\"none\"><path d=\"M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z\"\/><path d=\"M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z\"\/><path d=\"M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z\"\/><path d=\"M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z\"\/><path d=\"M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z\"\/><path d=\"M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z\"\/><path d=\"M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z\"\/><path d=\"M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z\"\/><path d=\"M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z\"\/><\/g><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/aif.amtbbs.org\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":3,"featured_media":7395,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-7393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-17"],"_links":{"self":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts\/7393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/comments?post=7393"}],"version-history":[{"count":1,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts\/7393\/revisions"}],"predecessor-version":[{"id":7396,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/posts\/7393\/revisions\/7396"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/media\/7395"}],"wp:attachment":[{"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/media?parent=7393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/categories?post=7393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aif.amtbbs.org\/index.php\/wp-json\/wp\/v2\/tags?post=7393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}