简体   繁体   English

如何在 oracle 中使用子查询

[英]How to use subqueries in oracle

Hello I'm trying to solve this question with a subquery:您好,我正在尝试使用子查询来解决这个问题:

Select names, service number, jobs and salaries of people working in the same city as HAVET. Select 与 HAVET 在同一城市工作的人员的姓名、服务编号、工作和薪水。 (havet is a name) (havet 是一个名字)

And I have only two table the first one is the emp table with the column (noserv, name, job, salaries) and the second one is the SERV table with the column (noserv, nameserv, city)我只有两个表,第一个是带有列(noserv,name,job,salary)的emp表,第二个是带有列(noserv,nameserv,city)的SERV表

I know that I have to use a subquery but I don't know how to do it.我知道我必须使用子查询,但我不知道该怎么做。

Semi-pseudocode (CTE won't work, obviously).半伪代码(显然,CTE 不起作用)。

with emp (noserv, name, job, salaries),
     serv (noserv, nameserv, city)
-- This is what you're looking for, I presume
select e.*
from emp e join serv s on e.noserv = s.noserv
where s.city = -- subquery returns city where HAVET lives
               (select s1.city 
                from serv s1 join emp e1 on e1.noserv = s1.noserv
                where e1.name = 'HAVET'
               );

Try this:尝试这个:

-- This is a normal query with a left join
select *
from emp e
left join s on e.noserv = s.noserv
where s.city = 

-- get Havet's city from the subquery.
(select s.city
from emp e
left join s on e.noserv = s.noserv
where e.name = 'HAVET') 

Try this one, change the column name according to your table and column names.试试这个,根据你的表和列名更改列名。

Select e.name,e.serviceNubmer,e.Job,e.salaries 
from emp e,serv s 
where 
e.noserv = s.noserv 
and s.city ='HAVET';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM