{"id":2324,"date":"2025-03-04T08:38:57","date_gmt":"2025-03-04T00:38:57","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=2324"},"modified":"2025-03-04T08:38:57","modified_gmt":"2025-03-04T00:38:57","slug":"sqlite-where-%e5%ad%90%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/03\/04\/sqlite-where-%e5%ad%90%e5%8f%a5\/","title":{"rendered":"SQLite WHERE \u5b50\u53e5"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><code>WHERE<\/code> \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a SQL \u67e5\u8be2\u4e2d\u7684\u6761\u4ef6\uff0c\u5e2e\u52a9\u8fc7\u6ee4\u8fd4\u56de\u7684\u8bb0\u5f55\u3002\u5b83\u7528\u4e8e\u5bf9\u67e5\u8be2\u7ed3\u679c\u8fdb\u884c\u7b5b\u9009\uff0c\u53ea\u8fd4\u56de\u7b26\u5408\u6761\u4ef6\u7684\u884c\u3002<code>WHERE<\/code> \u5b50\u53e5\u53ef\u4ee5\u7528\u4e8e <code>SELECT<\/code>\u3001<code>UPDATE<\/code>\u3001<code>DELETE<\/code> \u7b49 SQL \u8bed\u53e5\u4e2d\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u57fa\u672c\u7528\u6cd5<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 SQL \u67e5\u8be2\u4e2d\uff0c<code>WHERE<\/code> \u5b50\u53e5\u7d27\u8ddf\u5728 <code>FROM<\/code> \u5b50\u53e5\u4e4b\u540e\uff0c\u7528\u4e8e\u6307\u5b9a\u6761\u4ef6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE age &gt; 30;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u4ece <code>employees<\/code> \u8868\u4e2d\u9009\u53d6\u6240\u6709\u5e74\u9f84\u5927\u4e8e 30 \u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. \u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>WHERE<\/code> \u5b50\u53e5\u652f\u6301\u5404\u79cd\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u7528\u4e8e\u6bd4\u8f83\u5217\u7684\u503c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td><code>=<\/code><\/td><td>\u7b49\u4e8e<\/td><td><code>WHERE age = 30<\/code><\/td><\/tr><tr><td><code>!=<\/code> \u6216 <code>&lt;&gt;<\/code><\/td><td>\u4e0d\u7b49\u4e8e<\/td><td><code>WHERE age != 30<\/code> \u6216 <code>WHERE age &lt;&gt; 30<\/code><\/td><\/tr><tr><td><code>&gt;<\/code><\/td><td>\u5927\u4e8e<\/td><td><code>WHERE age &gt; 30<\/code><\/td><\/tr><tr><td><code>&lt;<\/code><\/td><td>\u5c0f\u4e8e<\/td><td><code>WHERE age &lt; 30<\/code><\/td><\/tr><tr><td><code>&gt;=<\/code><\/td><td>\u5927\u4e8e\u7b49\u4e8e<\/td><td><code>WHERE age &gt;= 30<\/code><\/td><\/tr><tr><td><code>&lt;=<\/code><\/td><td>\u5c0f\u4e8e\u7b49\u4e8e<\/td><td><code>WHERE age &lt;= 30<\/code><\/td><\/tr><tr><td><code>BETWEEN<\/code><\/td><td>\u8303\u56f4\u68c0\u67e5\uff0c\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5728\u4e24\u4e2a\u503c\u4e4b\u95f4\uff08\u5305\u542b\u8fb9\u754c\uff09<\/td><td><code>WHERE age BETWEEN 20 AND 30<\/code><\/td><\/tr><tr><td><code>IN<\/code><\/td><td>\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5b58\u5728\u4e8e\u4e00\u7ec4\u503c\u4e2d<\/td><td><code>WHERE age IN (20, 30, 40)<\/code><\/td><\/tr><tr><td><code>LIKE<\/code><\/td><td>\u6a21\u7cca\u5339\u914d\u5b57\u7b26\u4e32<\/td><td><code>WHERE name LIKE 'A%'<\/code><\/td><\/tr><tr><td><code>IS NULL<\/code><\/td><td>\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u4e3a NULL<\/td><td><code>WHERE name IS NULL<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE name LIKE 'A%';<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u9009\u51fa\u6240\u6709\u540d\u5b57\u4ee5 <code>A<\/code> \u5f00\u5934\u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u903b\u8f91\u8fd0\u7b97\u7b26<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>WHERE<\/code> \u5b50\u53e5\u53ef\u4ee5\u4f7f\u7528 <code>AND<\/code>, <code>OR<\/code>, <code>NOT<\/code> \u7b49\u903b\u8f91\u8fd0\u7b97\u7b26\u8fde\u63a5\u591a\u4e2a\u6761\u4ef6\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td><code>AND<\/code><\/td><td>\u4e24\u4e2a\u6761\u4ef6\u90fd\u4e3a\u771f\u65f6\u8fd4\u56de\u771f<\/td><td><code>WHERE age &gt; 20 AND name = 'John'<\/code><\/td><\/tr><tr><td><code>OR<\/code><\/td><td>\u4efb\u4e00\u6761\u4ef6\u4e3a\u771f\u65f6\u8fd4\u56de\u771f<\/td><td><code>WHERE age &lt; 20 OR age &gt; 60<\/code><\/td><\/tr><tr><td><code>NOT<\/code><\/td><td>\u5bf9\u6761\u4ef6\u53d6\u53cd<\/td><td><code>WHERE NOT age = 30<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE age &gt; 30 AND department = 'HR';<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u9009\u51fa\u6240\u6709\u5e74\u9f84\u5927\u4e8e 30 \u4e14\u5c5e\u4e8e <code>HR<\/code> \u90e8\u95e8\u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. <code>IS NULL<\/code> \u548c <code>IS NOT NULL<\/code><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>IS NULL<\/code> \u7528\u4e8e\u68c0\u67e5\u5217\u662f\u5426\u4e3a <code>NULL<\/code> \u503c\uff0c<code>IS NOT NULL<\/code> \u7528\u4e8e\u68c0\u67e5\u5217\u662f\u5426\u4e0d\u662f <code>NULL<\/code> \u503c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE department IS NULL;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u9009\u51fa\u6240\u6709\u6ca1\u6709\u6307\u5b9a\u90e8\u95e8\u7684\u5458\u5de5\uff08\u5373 <code>department<\/code> \u4e3a <code>NULL<\/code> \u7684\u5458\u5de5\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. <code>BETWEEN<\/code> \u64cd\u4f5c\u7b26<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>BETWEEN<\/code> \u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5728\u4e24\u4e2a\u7ed9\u5b9a\u7684\u8303\u56f4\u5185\uff08\u5305\u62ec\u8fb9\u754c\u503c\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE salary BETWEEN 3000 AND 5000;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u9009\u51fa\u6240\u6709\u5de5\u8d44\u5728 3000 \u5230 5000 \u4e4b\u95f4\u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. <code>IN<\/code> \u64cd\u4f5c\u7b26<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>IN<\/code> \u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5b58\u5728\u4e8e\u6307\u5b9a\u7684\u4e00\u7ec4\u503c\u4e2d\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE department IN ('HR', 'Finance', 'IT');<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u9009\u51fa\u6240\u6709\u5c5e\u4e8e <code>HR<\/code>\u3001<code>Finance<\/code> \u6216 <code>IT<\/code> \u90e8\u95e8\u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. <code>LIKE<\/code> \u64cd\u4f5c\u7b26<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>LIKE<\/code> \u7528\u4e8e\u8fdb\u884c\u6a21\u7cca\u5339\u914d\u3002\u5b83\u53ef\u4ee5\u4f7f\u7528\u901a\u914d\u7b26 <code>%<\/code>\uff08\u5339\u914d\u4efb\u610f\u5b57\u7b26\uff09\u548c <code>_<\/code>\uff08\u5339\u914d\u5355\u4e2a\u5b57\u7b26\uff09\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u901a\u914d\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td><code>%<\/code><\/td><td>\u5339\u914d\u4efb\u610f\u6570\u91cf\u7684\u5b57\u7b26\uff08\u5305\u62ec\u96f6\u4e2a\u5b57\u7b26\uff09<\/td><td><code>'A%'<\/code> \u5339\u914d\u6240\u6709\u4ee5 <code>A<\/code> \u5f00\u5934\u7684\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><code>_<\/code><\/td><td>\u5339\u914d\u5355\u4e2a\u5b57\u7b26<\/td><td><code>'A_<\/code>&#8216; \u5339\u914d\u6240\u6709\u4ee5 <code>A<\/code> \u5f00\u5934\uff0c\u540e\u9762\u8ddf\u4e00\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE name LIKE 'A%';<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u9009\u51fa\u6240\u6709\u540d\u5b57\u4ee5 <code>A<\/code> \u5f00\u5934\u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. \u4f7f\u7528 <code>OR<\/code> \u548c <code>AND<\/code> \u7ec4\u5408<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>OR<\/code> \u548c <code>AND<\/code> \u6765\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE age &gt; 30 AND (department = 'HR' OR department = 'Finance');<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u9009\u51fa\u6240\u6709\u5e74\u9f84\u5927\u4e8e 30 \u4e14\u5c5e\u4e8e <code>HR<\/code> \u6216 <code>Finance<\/code> \u90e8\u95e8\u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>9. \u7ec4\u5408\u591a\u4e2a\u6761\u4ef6<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u6761\u4ef6\u5728 <code>WHERE<\/code> \u5b50\u53e5\u4e2d\u8fdb\u884c\u590d\u6742\u7b5b\u9009\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM employees WHERE age &gt; 30 AND department = 'IT' AND salary &gt; 4000;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8be5\u67e5\u8be2\u5c06\u9009\u51fa\u6240\u6709\u5e74\u9f84\u5927\u4e8e 30\u3001\u5c5e\u4e8e <code>IT<\/code> \u90e8\u95e8\u4e14\u5de5\u8d44\u5927\u4e8e 4000 \u7684\u5458\u5de5\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u7528\u6cd5<\/strong>\uff1a\u7528\u4e8e\u5728\u67e5\u8be2\u4e2d\u7b5b\u9009\u7b26\u5408\u6761\u4ef6\u7684\u8bb0\u5f55\u3002<\/li>\n\n\n\n<li><strong>\u5e38\u89c1\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/strong>\uff1a<code>=<\/code>, <code>!=<\/code>, <code>><\/code>, <code>&lt;<\/code>, <code>BETWEEN<\/code>, <code>IN<\/code>, <code>LIKE<\/code>, <code>IS NULL<\/code> \u7b49\u3002<\/li>\n\n\n\n<li><strong>\u903b\u8f91\u8fd0\u7b97\u7b26<\/strong>\uff1a\u7528\u4e8e\u8fde\u63a5\u591a\u4e2a\u6761\u4ef6\uff0c\u5982 <code>AND<\/code>, <code>OR<\/code>, <code>NOT<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u8303\u56f4\u68c0\u67e5<\/strong>\uff1a\u4f7f\u7528 <code>BETWEEN<\/code> \u548c <code>IN<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u6a21\u7cca\u5339\u914d<\/strong>\uff1a\u4f7f\u7528 <code>LIKE<\/code> \u8fdb\u884c\u5b57\u7b26\u4e32\u5339\u914d\u3002<\/li>\n\n\n\n<li><strong>\u7a7a\u503c\u68c0\u67e5<\/strong>\uff1a\u4f7f\u7528 <code>IS NULL<\/code> \u548c <code>IS NOT NULL<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><code>WHERE<\/code> \u5b50\u53e5\u662f SQL \u67e5\u8be2\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u90e8\u5206\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7b5b\u9009\u548c\u7cbe\u786e\u63a7\u5236\u67e5\u8be2\u7ed3\u679c\u3002\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a SQL \u67e5\u8be2\u4e2d\u7684\u6761\u4ef6\uff0c\u5e2e\u52a9\u8fc7\u6ee4\u8fd4\u56de\u7684\u8bb0\u5f55\u3002\u5b83\u7528\u4e8e\u5bf9\u67e5\u8be2\u7ed3\u679c\u8fdb\u884c\u7b5b\u9009\uff0c\u53ea\u8fd4\u56de\u7b26\u5408\u6761\u4ef6\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-2324","post","type-post","status-publish","format-standard","hentry","category-sqlite"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=2324"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2324\/revisions"}],"predecessor-version":[{"id":2325,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2324\/revisions\/2325"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=2324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=2324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=2324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}