{"id":200145,"date":"2025-05-06T10:56:01","date_gmt":"2025-05-06T02:56:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200145\/"},"modified":"2025-05-06T10:56:01","modified_gmt":"2025-05-06T02:56:01","slug":"sql-mysql-%e4%bd%9c%e8%80%85%ef%bc%9a%e7%a9%86%e5%b0%bc%e5%a1%9e%e5%8d%a1%c2%b7%e4%b9%8c%e8%be%be%e7%93%a6%e6%8b%89%e5%b8%95%e8%92%82","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200145\/","title":{"rendered":"SQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>SQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300aSQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241015\/1728983566670e320ec1b4f.jpg\" class=\"aligncenter\"><\/p>\n<blockquote>\n<p>1.sql\u7b2c2\u90e8\u5206<\/p>\n<\/blockquote>\n<p>1.\u521b\u5efa\u7c7b\u8868<\/p>\n<pre>create table class(\n    class_id int primary key,\n    class_name varchar(50),\n    foreign key (teacher_id) references teacher(teacher_id)\n);\n<\/pre>\n<p>2.\u521b\u5efa\u6559\u5e08\u8868<\/p>\n<pre>create table teacher (\n    teacher_id int primary key,\n    teacher_name varchar(100),\n    age int,\n    subject varchar(50),\n    experience int\n);\n<\/pre>\n<p>3.\u5c06\u6559\u5e08\u6570\u636e\u63d2\u5165\u8868<\/p>\n<pre>insert into teacher(teacher_id,teacher_name,age,subject,experience)\nvalues\n(101, 'sk. sohana', 30, 'mathematics', 5),\n(102, 'u. munisekhar', 35, 'english', 8),\n(103, 'sk. nellu', 40, 'science', 10),\n(104, 'a. venu', 28, 'history', 3);\n<\/pre>\n<p>4.\u5c06\u7c7b\u6570\u636e\u63d2\u5165\u8868<\/p>\n<pre>insert into class(class_id,class_name,teacher_id)\n(9, 'math', 101),\n(10, 'english', 102),\n(11, 'science', 103),\n(12, 'history', 104);\n<\/pre>\n<h3> \u6559\u5e08\u684c <\/h3>\n<table>\n<thead>\n<tr>\n<th>teacher_id<\/th>\n<th>teacher_name<\/th>\n<th>age<\/th>\n<th>subject<\/th>\n<th>experience<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>101<\/td>\n<td>sk. sohana<\/td>\n<td>30<\/td>\n<td>mathematics<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td>102<\/td>\n<td>u. munisekhar<\/td>\n<td>35<\/td>\n<td>english<\/td>\n<td>8<\/td>\n<\/tr>\n<tr>\n<td>103<\/td>\n<td>sk. nellu<\/td>\n<td>40<\/td>\n<td>science<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>104<\/td>\n<td>a. venu<\/td>\n<td>28<\/td>\n<td>history<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>105<\/td>\n<td>s. jagadeesh<\/td>\n<td>28<\/td>\n<td>telugu<\/td>\n<td>3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3> \u7c7b\u8868 <\/h3>\n<table>\n<thead>\n<tr>\n<th>class_id<\/th>\n<th>class_name<\/th>\n<th>teacher_id<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>9<\/td>\n<td>math<\/td>\n<td>101<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>english<\/td>\n<td>102<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>science<\/td>\n<td>103<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>history<\/td>\n<td>104<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol>\n<li>\u4ececlass\u8868\u4e2d\u83b7\u53d6\u6570\u636e <\/li>\n<\/ol>\n<pre>select * from class;\n<\/pre>\n<pre>| class_id | class_name         | teacher_id |\n|----------|--------------------|------------|\n| 9        | math               | 101        |\n| 10       | english            | 102        |\n| 11       | science            | 103        |\n| 12       | history            | 104        |\n\n<\/pre>\n<ol>\n<li>\u4ece\u6559\u5e08\u8868\u4e2d\u83b7\u53d6\u6570\u636e 5\u5e74\u7ecf\u9a8c\u6559\u5e08 <\/li>\n<\/ol>\n<pre>select * from teacher whare experience &gt;5\n<\/pre>\n<pre>| teacher_id | teacher_name       | age | subject       | experience |\n|------------|--------------------|-----|---------------|------------|\n| 102        | u. munisekhar      | 35  | english       | 8          |\n| 103        | sk. nellu          | 40  | science       | 10         |\n<\/pre>\n<p>7.\u67e5\u627emunisekhar\u8001\u5e08\u8be6\u7ec6\u4fe1\u606f<\/p>\n<pre>select * from teacher where teacher_name='u. munisekhar'\n<\/pre>\n<pre>| teacher_id | teacher_name       | age | subject       | experience |\n|------------|--------------------|-----|---------------|------------|\n| 102        | u. munisekhar      | 35  | english       | 8          |\n<\/pre>\n<p>8.\u627e\u5230 sk. sohana\u8001\u5e08\u7684\u7ecf\u9a8c\uff1f<\/p>\n<pre>select experience from teacher where teacher_name='sk. sohana';\n<\/pre>\n<pre>| experience |\n|------------|\n|     8      |\n<\/pre>\n<p>9.\u67e5\u627e\u8001\u5e08\u7684\u59d3\u540d\u548c\u5e74\u9f84\uff0c\u5176\u4e2d\u5e74\u9f84\u4e3a 29 \u81f3 39<\/p>\n<pre>select name,age from teacher where age between 29 and 39;\n<\/pre>\n<pre>| teacher_name       | age |\n|--------------------|-----|\n| sk. sohana         | 30  | \n| u. munisekhar      | 35  | \n<\/pre>\n<p>10.\u67e5\u627e\u73ed\u7ea7\u540d\u79f0\u548c\u8001\u5e08\u59d3\u540d\u4ee5\u4f7f\u7528\u5de6\u8fde\u63a5<\/p>\n<pre>select class.class_name, teacher.teacher_name\nfrom class\nright join teacher on class.teacher_id=teacher.teacher_id;\n<\/pre>\n<pre>| class_name | teacher_name       |\n|------------|--------------------|\n| math       | sk. sohana         |\n| english    | u. munisekhar      |\n| science    | sk. nellu          |\n| history    | a. venu            |\n<\/pre>\n<p>11.\u67e5\u627e\u73ed\u7ea7\u540d\u79f0\u548c\u6240\u6709\u6559\u5e08\u59d3\u540d\u4ee5\u4f7f\u7528\u53f3\u8fde\u63a5<\/p>\n<pre>select class.class_name, teacher.teacher_name\nfrom class\nright join teacher on class.teacher_id=teacher.teacher_id;\n<\/pre>\n<pre>| class_name | teacher_name       |\n|------------|--------------------|\n| math       | sk. sohana         |\n| english    | u. munisekhar      |\n| science    | sk. nellu          |\n| history    | a. venu            |\n| null       | s. jagadeesh       |\n<\/pre>\n<p>12.\u67e5\u627e\u73ed\u7ea7\u540d\u79f0\u548c\u6559\u5e08\u59d3\u540d\u4ee5\u4f7f\u7528\u5185\u8fde\u63a5<\/p>\n<pre>select class.class_name, teacher.teacher_name\nfrom class\ninner join teacher on class.teacher_id=teacher.teacher_id;\n<\/pre>\n<pre>| class_name | teacher_name       |\n|------------|--------------------|\n| math       | sk. sohana         |\n| english    | u. munisekhar      |\n| science    | sk. nellu          |\n| history    | a. venu            |\n<\/pre>\n<p>13.\u67e5\u627emunisekhar\u73ed\u7ea7\u663e\u793a\u4ed6\u7684\u59d3\u540d\u548c\u73ed\u7ea7<\/p>\n<pre>select teacher.teacher.name, class.class_name\nfrom teacher \nright join class on teacher.teacher_id=class.teacher_id\nwhere teacher.teacher_name = 'u. munisekhar';\n<\/pre>\n<pre>| teacher_name       | class_name |\n|--------------------|------------|\n| U. Munisekhar      | English    |\n<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aSQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664 <\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>SQL || MySQL ||\u4f5c&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200145","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200145"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200145\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}