当前位置:网站首页>7. sub query
7. sub query
2022-04-23 07:40:00 【Ah Dai cloth clothes cool】
7. Subquery
1. Check the wage ratio 7566 High employee information
select *
from emp
where sal>(select sal from emp where empno=7566);
2. Query the employee's number 、 full name 、 Department name
select empno,ename,(select dname from dept where deptno=e.deptno)
from emp e;
3. Check the wage ratio 7654 high , At the same time with 7900 Information about employees engaged in the same work
select *
from emp
where sal>(
select sal from emp where empno=7654
) and job=(
select job from emp where empno=7900
);
4. Check the name of the lowest paid employee 、 Work 、 Wages
select ename,job,sal
from emp
where sal=(select min(sal) from emp);
5. Query the information of employees whose salary is higher than the average salary of the company
select *
from emp
where sal>(select avg(sal) from emp);
6. Check the number and minimum wage of each department , The minimum wage is required to be greater than or equal to the Department 30 The minimum wage
select deptno,min(sal)
from emp
group by deptno
having min(sal)>=(
select min(sal) from emp where deptno=30
);
7. Query the name of the Department 、 The number of employees in the Department 、 The average wage of the Department 、 The name of the lowest paid employee in the Department
select
(select dname from dept where deptno=e.deptno) dname,
count(empno),
avg(sal),
(select ename from emp where sal=min(e.sal)) ename
from emp e
group by deptno;
8. Check the lowest average wage job and average wage
select job,avg(sal)
from emp
group by job
having avg(sal)=(
select min(t.avg) from (select avg(sal) avg from emp group by job) t
);
9. Query the department number is greater than or equal to 20 Of employees
select * from emp
where deptno>=20;
select * from emp
where deptno in (
select deptno from dept where deptno>=20
);
10. Query salary and department 20 Any employee in the same employee information
select * from emp
where sal in (
select sal from emp where deptno=20
);
11. Find out that the salary of employees engaged in sales is greater than 1500 The employees'
select *
from (select * from emp where job='saleman') t
where t.sal>1500;
版权声明
本文为[Ah Dai cloth clothes cool]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230622239337.html
边栏推荐
- Machine vision series (02) -- tensorflow2 3 + win10 + GPU installation
- 嵌入式相关面经(一)
- Applet Wx Previewmedia related problem solving - Daily stepping on the pit
- 快速傅里叶变换FFT简明教程
- 可视化常见问题解决方案(八)共享绘图区域问题解决方案
- LATEX公式注意事项
- anaconda3安装
- [牛客练习赛68]牛牛的粉丝(矩阵快速幂之循环矩阵优化)
- Reflection on the systematic design of Android audio and video caching mechanism
- 推导式与正则式
猜你喜欢
随机推荐
Transformer的pytorch实现
嵌入式相关面经(一)
学习笔记6-几种深度学习卷积神经网络的总结
Object. Create() principle, object Create() specification, handwritten object create(),Object. Create() usage
[COCI]Lampice (二分+树分治+字符串哈希)
VScode
P2257 YY的GCD(莫比乌斯反演)
Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
获取字符格式的当前时间
ESP32学习-GPIO的使用与配置
Object.create()原理,Object.create()规范,手写Object.create(),Object.create()用法
Javscript gets the real suffix of the file
直观理解熵
反思|开启B站少女心模式,探究APP换肤机制的设计与实现
What is a closure?
【自我激励系列】你永远不会准备好
javscript获取文件真实后缀名
特殊成员与魔法方法
安装tui-editor失败,快速解决方案
H5案例开发