sql查询语句的提问

来源:百度知道 编辑:UC知道 时间:2024/05/02 12:45:40
sql查询语句的提问
表1
employee_name street city
Smith 1st NewYork
Jack 2nd NewYork
Allen 2nd NewYork
John 1st Washington
Nash 2nd San Diego
Blerk 5Avn Los Angels
表2
employee_name manager_name
Smith Jack
Jack John
Allen Nash
John NULL
Nash NULL
Blerk Nash
找出那些职员,他和自己的经理居住在同一城市、同一街区

表3
employee_name company_name salary
Smith First Bank Corporation 20000
Jack First Bank Corporation 30000
Allen Small Bank Corporation 55000
John First Bank Corporation 40000
Nash Small Bank Corporation 35000
Blerk Small Bank Corporation 24000
Smith Small Bank Corporation 20000

找出那些职员,它们的收入比他们公司职员的平均收入高

一、此语句查询的是 员工的公司和收入情况:
select *
from 表3
where salary>(
select avg(salary)
from 表3
group by company_name
);

二、此语句查询员工的基本情况
select *
from 表1
where employee_name in (select employee_name
from 表3
where salary>
(
select avg(salary)
from 表3
group by company_name
)
);

你可以根据你的具体需要进行选择,如果希望查询更多的信息 则需要再进行多表连接查询。