多表查询_子查询概述和多表查询_子查询情况1&情况2&情况3
2024-09-07 02:15:22
子查询
概念:查询中嵌套查询,称嵌套查询为子查询
-- 查询工资最高的员工信息
-- 1.查询最高的工资是多少 9000
select max(salary) from emp;
-- 查询员工信息,并且工资等于9000的
select * from emp where salary =9000;
-- 一条sql就完成这个操作 子查询
select * from emp where salary = (select max(salary) from emp);
子查询的不同情况
1.子查询的结果是单行单列的:
子查询可以作为条件,使用运算符去判断
-- 查询员工工资小于平均工资的人
select * from emp where salary < (select avg(salary) from emp);
2.子查询的结果是多行单列的:
子查询可以作为条件,使用运算符in来判断
-- 查询"财务部"和"市场部"所有的员工信息
select id from dept where name = "财务部" or name = "市场部";
select * from emp where dept_id = 3 or dept_id = 2;
-- 子查询
select * from emp where dept_id in (select id from dept where name = "市场部" or name = "财务部");
3.子查询的结果是多行多列的:
查询员工入职日期是2011-11-11日之后的员工信息和部门信息
select * from dept,(select * from emp where emp.join_date > "2011-11-11") t2 where dept.id = t2.dept_id;
最新文章
- linux(centOS)下安装Oracle步骤
- ios培训机构排名
- 使用TabPageIndicator的样式问题
- python学习笔记-Day6(1)
- sqlserver同步表的脚本
- 关于jsp利用EL和struts2标签来遍历ValueStack的东东 ------>; List<;Map<;K,V>;>; 以及 Map<;K,<;List<;xxx>;>;>; 的结构遍历
- Func 委托
- poj2411Mondriaan&#39;s Dream(状压)
- C#核编之字符串类型介绍与操作
- Code 16K 码
- 注册表中LEGACY残留项的清理技巧
- Swagger服务API治理详解
- RPO(Relative Path Overwrite)
- 初学Python——文件操作第三篇
- 在前台根据传过来的XX级别的数字转XX的名字
- Nginx源码结构及如何处理请求
- 2017-8-20 HTTP协议
- ICCV2013 录用论文(目标跟踪相关部分)(转)
- JS中的事件冒泡——总结
- [算法]用JAVA实现快速排序
热门文章
- Ansible的参数介绍
- a commponent required a bean of type XXXXXX that could not be found-2022新项目
- 零基础学Java第二节(运算符、输入、选择流程控制)
- 【多线程】守护线程	Daemon
- 【多线程】观测线程状态	getState()
- Python数据分析--Numpy常用函数介绍(2)
- Element UI DatePicker 时间跨度限制在同一个月内
- Windows环境下启动Redis报错:Could not create server TCP listening socket 127.0.0.1:6379: bind: 操作成功完成。(已解决)
- 值得注意的: c++动态库、静态库、弱符号__attribute__((weak))以及extern之间的关系
- MUI+html5的plus.webview页面传值在电脑浏览器上不可见