当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Applet Wx Previewmedia related problem solving - Daily stepping on the pit
1.查看数据库和表
12.约束
Discussion on arrow function of ES6
HuggingFace
Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference
CSDN很火的汤小洋老师全部课程总共有哪些(问号问号问号)
5.SQL99标准:内连接和外连接
数据分析入门 | kaggle泰坦尼克任务(三)—>探索数据分析
理解补码的要点
[2020WC Day2]F.采蘑菇的克拉莉丝(子树和查询、轻重儿子思想)
Applet newline character \ nfailure problem resolution - Daily pit stepping
开发板如何ping通百度
[COCI]Lampice (二分+树分治+字符串哈希)
[self motivation series] you'll never be ready
可视化常见问题解决方案(八)数学公式
积性函数与迪利克雷卷积
页面动态显示时间(升级版)
Authorization+Token+JWT









