显示具有帐户SQL Query Oracle 10G的客户的名称

问题描述 投票:-1回答:1
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显示客户名称及其所处理员工的姓名**

sql database oracle oracle10g qsqlquery
1个回答
0
投票

Q1是在联结表cust_id中对has的简单查找:

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

此短语为:选择在has表中至少具有一个条目的客户。

关于第二季度:您的数据结构没有显示雇员的迹象(我们拥有的只是客户和客户),因此无法根据您提供的信息来回答。您可能想问一个[[new问题,为涉及的表提供示例数据,以及所需的结果您当前尝试解决该问题的方法。

© www.soinside.com 2019 - 2024. All rights reserved.