显示拥有账户的客户名称 SQL 查询 Oracle 10G

Show the names of customers that have accounts SQL Query Oracle 10G

create table customer
    (cust_id    integer     not null,
    cust_name   char(20)    not null ,
    cust_address    varchar2(200)   ,
    emp_id      integer     not null,
        constraint pk_customer primary key(cust_id)
    );
create table account
    (account_number integer     not null,
    account_balance number(8,2) not null,
    constraint pk_acount primary key(account_number)
    );

create table has
    (cust_id integer not null,
     account_number integer not null,
     constraint pk_has
       primary key(cust_id, account_number) )

alter table has
add constraint fk_account_has foreign key(account_number) 
references account(account_number);

alter table has 
add constraint fk_customer_has foreign key(cust_id) 
references customer(cust_id);

Q1 显示拥有账户的客户姓名

Q2 显示客户名称以及与他们打交道的员工姓名**

Q1 是对 cust_id 的简单查找 table has:

select c.cust_name
from customer c
where exists (select 1 from has h where h.cust_id = c.cust_id)

此短语为:select 在 has table 中至少有一个条目的客户。

关于Q2:你的数据结构中没有员工的迹象(我们只有客户和账户),所以根据你提供的信息无法回答这个问题。您可能想为此提出一个 new 问题,为所涉及的 table 提供示例数据,以及您想要的结果 当前尝试解决问题。