我有以下表格:
CREATE TABLE CUSTOMERS
(customerID INT PRIMARY KEY,
customerFullName VARCHAR(20) NOT NULL);
CREATE TABLE VEHICLES
(vehicleVIN VARCHAR(25) PRIMARY KEY,
vehicleMake VARCHAR(15) NOT NULL);
CREATE TABLE SALES
(saleID INT PRIMARY KEY,
customerID INT,
vehicleVIN VARCHAR(25));
CONSTRAINT SALES_FK1 FOREIGN KEY (customerID) REFERENCES CUSTOMERS(customerID),
CONSTRAINT SALES_FK2 FOREIGN KEY (vehicleVIN) REFERENCES VEHICLES(vehicleVIN));
并构建了以下查询来运行这些表:
SELECT VEHICLES.vehicleMake, CUSTOMERS.customerFullName
FROM SALES
JOIN CUSTOMERS on SALES.customerID = CUSTOMERS.customerID
JOIN(
SELECT SALES.vehicleVIN, VEHICLES.vehicleMake
FROM SALES
JOIN VEHICLES ON SALES.vehicleVIN = VEHICLES.vehicleVIN
GROUP BY SALES.vehicleVIN, VEHICLES.vehicleMake
HAVING COUNT(SALES.vehicleVIN) >= ALL
(SELECT COUNT(SALES.vehicleVIN)
FROM SALES
INNER JOIN VEHICLES ON SALES.vehicleVIN=VEHICLES.vehicleVIN
GROUP BY VEHICLES.vehicleMake))
VEHICLES ON SALES.vehicleVIN = VEHICLES.vehicleVIN
ORDER BY CUSTOMERS.customerFullName;
当我在 SQL Fiddle 中运行它时,它完美执行并提供正确的输出(一列显示购买最多的车辆制造商,另一列显示购买该车辆制造商的每个人的 customerFullName)。
当我在 NOVA (Oracle) 中运行它时,它只是说“没有选择行”两者之间的语法有区别吗?我需要更改我的代码吗?谢谢!