{"id":6667,"date":"2024-11-14T11:47:56","date_gmt":"2024-11-14T03:47:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6667\/"},"modified":"2024-11-14T11:47:56","modified_gmt":"2024-11-14T03:47:56","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:\/\/fwq.ai\/blog\/6667\/","title":{"rendered":"SQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172881954836922.jpg\" class=\"aligncenter\" title=\"SQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482\u63d2\u56fe\" alt=\"SQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482\u63d2\u56fe\" \/><\/p>\n<blockquote><p>\n  1.sql\u7b2c2\u90e8\u5206\n<\/p><\/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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<pre>| teacher_id | teacher_name       | age | subject       | experience |\n|------------|--------------------|-----|---------------|------------|\n| 102        | u. munisekhar      | 35  | english       | 8          |\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<pre>| experience |\n|------------|\n|     8      |\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<pre>| teacher_name       | age |\n|--------------------|-----|\n| sk. sohana         | 30  | \n| u. munisekhar      | 35  | \n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236     <\/p>\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>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236    <\/p>\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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236     <\/p>\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>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236   <\/p>\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<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<pre>| teacher_name       | class_name |\n|--------------------|------------|\n| U. Munisekhar      | English    |\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSQL || MySQL ||\u4f5c\u8005\uff1a\u7a46\u5c3c\u585e\u5361\u00b7\u4e4c\u8fbe\u74e6\u62c9\u5e15\u8482\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.sql\u7b2c2\u90e8\u5206 1.\u521b\u5efa\u7c7b\u8868 create table class( class_id int primary key, class_name varchar(50), foreign key (teacher_id) references teacher(teacher_id) ); \u767b\u5f55\u540e\u590d\u5236 2.\u521b\u5efa\u6559\u5e08\u8868 create table teacher ( teacher_id int primary key, teacher_name varchar(100), age int, subject varchar(50), experience int ); \u767b\u5f55\u540e\u590d\u5236 3.\u5c06\u6559\u5e08\u6570\u636e\u63d2\u5165\u8868 insert into teacher(teacher_id,teacher_name,age,subject,experience) values (101, &#8216;sk. sohana&#8217;, 30, &#8216;mathematics&#8217;, 5), (102, &#8216;u. munisekhar&#8217;, 35, &#8216;english&#8217;, 8), (103, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6667","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6667"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6667\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}