当前位置: 首页 > news >正文

多表查询-练习

image

image

-- 多表查询-练习1
-- 1.查询员工的姓名、年龄、职位、部门信息。(隐式内连接)
select e.name,e.age,e.job,d.* from emp e ,dept d where e.dept_id = d.id;
-- 2.查询年龄小于30岁的员工姓名、年龄、职位、部门信息。(显式内连接)
select e.name,e.age,e.job,d.* from emp e inner join dept d on e.dept_id = d.id where e.age < 30;
-- 3.查询拥有员工的部门ID、部门名称。
select distinct d.id,d.name from emp e ,dept d where e.dept_id = d.id;
-- 4.查询所有年龄大于40岁的员工,及其归属的部门名称;如果员工没有分配部门,也需要展示出来。
select e.name,d.name from emp e left join dept d on d.id = e.dept_id where e.age>40;
-- 5.查询所有员工的工资等级。
-- 表 emp,salgrade
-- 连接条件:emp.salary >= salgrade.losal and emp.salary <= salgrade.hisal
select e.*,s.grade from emp e,salgrade s where e.salary >= s.losal and e.salary <= s.hisal;
select e.*,s.grade from emp e,salgrade s where e.salary between s.losal and s.hisal;
-- 6.查询"研发部"所有员工的信息及工资等级。
-- 表 emp,salgrade,dept
-- 连接条件 emp.salary between salgrade.losal and salgrade.hisal,emp.dept_id = dept.id
select e.*,s.grade from emp e, dept d ,salgrade s  where e.dept_id = d.id and (e.salary between s.losal and s.hisal) and d.name = '研发部';
-- 7.查询"研发部"员工的平均工资.
select avg(salary) from emp e,dept d where e.dept_id = d.id and d.name = '研发部';
-- 8.查询工资比"灭绝"高的员工信息。
select salary from emp where name = '灭绝';
select * from emp where salary > (select salary from emp where name = '灭绝');
-- 9.查询比平均薪资高的员工信息。
select avg(salary) from emp;
select * from emp where salary > (select avg(salary) from emp);
-- 10.查询低于本部门平均工资的员工信息。
-- a.查询指定部门的平均薪资
select avg(e1.salary) from emp e1 where dept_id = 1;
select avg(e1.salary) from emp e1 where dept_id = 2;
-- b.查询低于本部门平均工资的员工信息
select * from emp e2 where e2.salary < (select avg(e1.salary) from emp e1 where e1.dept_id = e2.dept_id);
-- 11.查询所有的部门信息,并统计部门的员工人数。
-- a.查询指定部门的人数
select count(*) from emp where dept_id = 1;
-- b.查询所有的部门信息,并统计部门的员工人数。
select d.*,(select count(*) from emp e where e.dept_id = d.id) '人数' from dept d ;
-- 12.查询所有学生的选课情况,展示出学生名称,学号,课程名称
-- 表  student course student_course
-- 连接 student.id = student_course.studentid    course.id = student_course.courseid
select s.name,s.no,c.name from student s, student_course sc,course c where s.id = sc.studentid and c.id = sc.courseid;

image

image

10-12题好好理解

http://www.hskmm.com/?act=detail&tid=39047

相关文章:

  • 实验3:卷积神经网络 - OUC
  • 使用 Docker Compose 在 CentOS 7 单机服务器上部署多实例 MinIO 集群
  • 102302147傅乐宜作业1
  • 多智能体大模型在农业中的应用研究与展望
  • 嵌入式基础作业--第七周--IIC协议采集温湿度与OLED显示
  • Nature子刊 | 基于生物学信息的神经网络
  • 软件开发(10.23)
  • 2025年项目总延期?这30款项目进度管理软件一定有一款适合你!
  • Educational Codeforces Round 66 (Rated for Div. 2) A~F
  • 鲁东大学提出可解释的自适应集成机器学习全基因组选择算法用于小麦产量性状关键SNPs筛选
  • 台球厅收银台押金原路退回系统押金预授权—东方仙盟 - 详解
  • if 语句
  • 数论专题小记
  • 机械臂和相机的9点标定原理
  • 遗传改良中的核心技术:交配设计
  • 《程序员修炼之道:从小工到专家》笔记1
  • 语言是火,视觉是光:论两种智能信号的宿命与人机交互的未来 - 教程
  • 书籍推荐 | 《数量遗传学》(王建康)
  • Plant Com | 一种新的多源数据(基因组、表型和跨环境)融合的基因组预测框架-GPS
  • 科普报告:分子标记辅助选择(MAS)育种
  • 作物遗传育种中的多亲本互交群体(MAGIC)
  • 联邦大型语言模型、多智能体大型语言模型是什么? - 详解
  • 一个用于自动化基因表达分析的多智能体框架GenoMAS
  • AI巨头动态:从OpenAI收购到Meta裁员,我们看到了什么?
  • 小麦锈病抗性全景图及其在育种设计中的应用
  • CF1896F
  • Nature Methods | 大语言模型基因集分析工具GeneAgent
  • 50年的玉米育种改良,是如何应对气候变化的?
  • 刷题日记—洛谷数组题单—幻方
  • 基因组选择(GS)如何加速作物遗传增益?