[英]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 顯示賬號為101和賬號為102的客戶的所有信息
Q2 顯示所有賬戶余額大於 500 的客戶的帳號和客戶 ID。
Q3 顯示賬戶余額不等於 500 的客戶的所有信息。
那將是這樣的:
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);
我建議您現在停止閱讀,然后-查看第一個示例-嘗試自己編寫接下來的 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.