表仓库的表结构
CREATE TABLE Warehouse (
wID NUMBER(25) ,
Location VARCHAR2(70) ,
Num_Employees NUMBER(25) ,
Stock NUMBER(25) ,
PRIMARY KEY (wID)
);
CREATE SEQUENCE WAREHOUSE_SEQ
START WITH 1
INCREMENT BY 1
NOMAXVALUE;
INSERT INTO Warehouse (wID, Location, Num_Employees, Stock)
VALUES (WAREHOUSE_SEQ.nextval , 'Dallas', '3', '13');
INSERT INTO Warehouse (wID, Location, Num_Employees, Stock)
VALUES (WAREHOUSE_SEQ.nextval , 'Denver', '3', '07');
INSERT INTO Warehouse (wID, Location, Num_Employees, Stock)
VALUES (WAREHOUSE_SEQ.nextval , 'Detroit', '3', '09');
INSERT INTO Warehouse (wID, Location, Num_Employees, Stock)
VALUES (WAREHOUSE_SEQ.nextval , 'Phoenix', '3', '14');
INSERT INTO Warehouse (wID, Location, Num_Employees, Stock)
VALUES (WAREHOUSE_SEQ.nextval , 'Atlanta', '3', '07');
查询:
SELECT DISTINCT
Orders.wID,
person.name,
Employee.*,
Warehouse.wID
FROM person
INNER JOIN Orders ON Orders.wID = Warehouse.wID
INNER JOIN Warehouse ON Warehouse.LOCATION=Employee.WORK_LOCATION
INNER JOIN Employee ON Employees.ETYPE='Manager'
WHERE Employee.EID = person.Id;
答案 0 :(得分:2)
问题是你的第一次加入: 'FROM INNER JOIN Orders ON Orders.wID = Warehouse.wID'
目前“仓库”表尚未提供,但您已经在“开启”部分提及了它。
答案 1 :(得分:1)
试试这个..
SELECT DISTINCT Orders.wID, person.name, Employee.*, Warehouse.wID
FROM person INNER JOIN Employee
ON person.Id = Employee.EID
INNER JOIN Warehouse
ON Warehouse.LOCATION = Employee.WORK_LOCATION
INNER JOIN Orders
ON Orders.wID = Warehouse.wID
WHERE Employees.ETYPE ='Manager';
答案 2 :(得分:1)
试试这样:
SELECT DISTINCT Orders.wID,
person.NAME,
Employee.*,
Warehouse.wID
FROM person
INNER JOIN Employee ON Employee.EID = person.Id;
INNER JOIN Warehouse ON Warehouse.LOCATION = Employee.WORK_LOCATION
INNER JOIN Orders ON Orders.wID = Warehouse.wID
WHERE Employees.ETYPE = 'Manager'