SQL || MySQL ||作者:穆尼塞卡·乌达瓦拉帕蒂

心靈之曲
发布: 2024-10-13 19:39:05
转载
1222人浏览过

sql || mysql ||作者:穆尼塞卡·乌达瓦拉帕蒂

1.sql第2部分

1.创建类表

create table class(
    class_id int primary key,
    class_name varchar(50),
    foreign key (teacher_id) references teacher(teacher_id)
);
登录后复制

2.创建教师表

create table teacher (
    teacher_id int primary key,
    teacher_name varchar(100),
    age int,
    subject varchar(50),
    experience int
);
登录后复制

3.将教师数据插入表

insert into teacher(teacher_id,teacher_name,age,subject,experience)
values
(101, 'sk. sohana', 30, 'mathematics', 5),
(102, 'u. munisekhar', 35, 'english', 8),
(103, 'sk. nellu', 40, 'science', 10),
(104, 'a. venu', 28, 'history', 3);
登录后复制

4.将类数据插入表

insert into class(class_id,class_name,teacher_id)
(9, 'math', 101),
(10, 'english', 102),
(11, 'science', 103),
(12, 'history', 104);
登录后复制

教师桌

teacher_id teacher_name age subject experience
101 sk. sohana 30 mathematics 5
102 u. munisekhar 35 english 8
103 sk. nellu 40 science 10
104 a. venu 28 history 3
105 s. jagadeesh 28 telugu 3

类表

class_id class_name teacher_id
9 math 101
10 english 102
11 science 103
12 history 104
  1. 从class表中获取数据
select * from class;
登录后复制
| class_id | class_name         | teacher_id |
|----------|--------------------|------------|
| 9        | math               | 101        |
| 10       | english            | 102        |
| 11       | science            | 103        |
| 12       | history            | 104        |

登录后复制
  1. 从教师表中获取数据 5年经验教师
select * from teacher whare experience >5
登录后复制
| teacher_id | teacher_name       | age | subject       | experience |
|------------|--------------------|-----|---------------|------------|
| 102        | u. munisekhar      | 35  | english       | 8          |
| 103        | sk. nellu          | 40  | science       | 10         |
登录后复制

7.查找munisekhar老师详细信息

select * from teacher where teacher_name='u. munisekhar'
登录后复制
| teacher_id | teacher_name       | age | subject       | experience |
|------------|--------------------|-----|---------------|------------|
| 102        | u. munisekhar      | 35  | english       | 8          |
登录后复制

8.找到 sk. sohana老师的经验?

卡拉OK视频制作
卡拉OK视频制作

卡拉OK视频制作,在几分钟内制作出你的卡拉OK视频

卡拉OK视频制作 178
查看详情 卡拉OK视频制作
select experience from teacher where teacher_name='sk. sohana';
登录后复制
| experience |
|------------|
|     8      |
登录后复制

9.查找老师的姓名和年龄,其中年龄为 29 至 39

select name,age from teacher where age between 29 and 39;
登录后复制
| teacher_name       | age |
|--------------------|-----|
| sk. sohana         | 30  | 
| u. munisekhar      | 35  | 
登录后复制

10.查找班级名称和老师姓名以使用左连接

select class.class_name, teacher.teacher_name
from class
right join teacher on class.teacher_id=teacher.teacher_id;
登录后复制
| class_name | teacher_name       |
|------------|--------------------|
| math       | sk. sohana         |
| english    | u. munisekhar      |
| science    | sk. nellu          |
| history    | a. venu            |
登录后复制

11.查找班级名称和所有教师姓名以使用右连接

select class.class_name, teacher.teacher_name
from class
right join teacher on class.teacher_id=teacher.teacher_id;
登录后复制
| class_name | teacher_name       |
|------------|--------------------|
| math       | sk. sohana         |
| english    | u. munisekhar      |
| science    | sk. nellu          |
| history    | a. venu            |
| null       | s. jagadeesh       |
登录后复制

12.查找班级名称和教师姓名以使用内连接

select class.class_name, teacher.teacher_name
from class
inner join teacher on class.teacher_id=teacher.teacher_id;
登录后复制
| class_name | teacher_name       |
|------------|--------------------|
| math       | sk. sohana         |
| english    | u. munisekhar      |
| science    | sk. nellu          |
| history    | a. venu            |
登录后复制

13.查找munisekhar班级显示他的姓名和班级

select teacher.teacher.name, class.class_name
from teacher 
right join class on teacher.teacher_id=class.teacher_id
where teacher.teacher_name = 'u. munisekhar';
登录后复制
| teacher_name       | class_name |
|--------------------|------------|
| U. Munisekhar      | English    |
登录后复制

以上就是SQL || MySQL ||作者:穆尼塞卡·乌达瓦拉帕蒂的详细内容,更多请关注php中文网其它相关文章!

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:dev.to网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号