0

我有以下表格:

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) 中运行它时,它只是说“没有选择行”两者之间的语法有区别吗?我需要更改我的代码吗?谢谢!

4

1 回答 1

0

自己回答。我在 SQL Fiddle 和 NOVA 之间的插入语句中提取的数据存在细微差异。问题是我的错,据我现在所知,一切都在正常运行。

我在 SQL fiddle 中的插入语句重新使用了一些车辆 VIN 号码,这有助于我编写的查询的成功,但是对于我想要完成的查询不正确。打开另一个问题来讨论该特定问题。

底线:我不认为它们是 NOVA DB 语法和 SQL Fiddle 语法之间的任何主要区别。一切都很好!

于 2018-02-01T18:52:17.020 回答