简体   繁体   English

Oracle Database 10G Query待解决

[英]Oracle Database 10G Query to be solved

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);

alter table customer 
add constraint fk_employee_customer foreign key(emp_id) 
references employee(emp_id);

Q1 Show all the information about the customers with account number 101 and account number 102 Q1 显示账号为101和账号为102的客户的所有信息

Q2 Show the account numbers and the customer IDs for all customers with account balance higher than 500. Q2 显示所有账户余额大于 500 的客户的帐号和客户 ID。

Q3 Show all the information about the customers with account balances that differ from 500. Q3 显示账户余额不等于 500 的客户的所有信息。

That would be something like this:那将是这样的:

select c.cust_id, c.cust_address, c.cust_address
from customer c join has h on h.cust_id = c.cust_id
where h.account_number in (101, 102);

I suggest you STOP reading now and - looking at the first example - try to write the next 2 queries yourself.我建议您现在停止阅读,然后-查看第一个示例-尝试自己编写接下来的 2 个查询。

select c.cust_id, h.account_Number
from customer c join has h on h.cust_id = c.cust_id
join account a on a.account_number = h.account_number
where a.account_balance > 500;

select c.cust_id, c.cust_address, c.cust_address
from customer c join has h on h.cust_id = c.cust_id
join account a on a.account_number = h.account_number
where a.account_balance <> 500;

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

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