SQL中的连接问题

来源:百度知道 编辑:UC知道 时间:2024/09/21 21:52:23
一、有以下三个关系:
SALESPERSON(销售人员)
Name Age Salary
Abel 63 120,000
Baker 38 42,000
Jones 26 36,000
Murphy 42 50,000
Zenith 59 118,000
Kobad 27 34,000
ORDER(定单)
Number CustName SalespersonName Amount
100 Abernathy Construction Zenith 560
200 Abernathy Construction Jones 1800
300 Manchester Lumber Abel 480
400 Amalgamated Housing Abel 2500
500 Abernathy Construction Murphy 6000
600 Tri-city Builders Abel 700
700 Manchester Lumber Jones 1 50
CUSTOMER(顾客)
Name City Industry Type
Abernathy Construction Willow B
Manchester Lumber Manchester F
Tri-city Builders Memphis B
Amalgamated Housing Memphis B
显示和在MEMPHIS中的一个客户有订单的Salespeople的年龄(使用连接)。

SELECT NAME,AGE FROM SALESPERSON
WHERE NAME IN (
SELECT SALESPERSONNAME FROM "ORDER"
WHERE CUSTNAME IN (SELECT NAME FROM CUSTOMER WHERE UPPER(INDUSTRY)='MEMPHIS'));

多表查询吗?
select a.Age from a SALESPERSON,b ORDER,c CUSTOMER
where c.City='MEMPHIS' and b.CustName=c.Name and b.SalespersonName=a.Name