我正在尝试显示满足他们提供的每个库存商品的所有供应商的供应商代码,供应商名称和邮政编码 价格高于所有库存商品的平均值。
我已经尝试了一段时间,这是我能想到的最好的,虽然它不起作用
SELECT SuppName, SuppCode, Postcode
FROM Suppliers
WHERE Suppliers.SuppCode = (
SELECT SuppCode
FROM Stocks
WHERE Suppliers.SuppCode = Stocks.SuppCode
GROUP BY SuppCode
HAVING MIN(Price) > AVG(Price)
);
如果有人能给我一个关于我出错的正确方向的暗示,那将非常感激。
create table Stocks
(StockNo number(6) not null primary key,
StoreCode varchar2(6) not null,
Description varchar2(24),
Quantity number(6),
Units varchar2(12),
Reorder number(6),
foreign key (StoreCode)
references Stores(StoreCode));
create table Suppliers
(SuppCode varchar2(4) not null primary key,
SuppName varchar2(30),
Street varchar2(24),
Town varchar2(16),
County varchar2(16),
PostCode varchar2(10),
TelNo varchar2(16),
FaxNo varchar2(16))
cluster SupplyData(SuppCode);
答案 0 :(得分:1)
要获取这些耗材的代码,我会去聚合。你似乎想要:
SELECT s.SuppCode
FROM Stocks s
GROUP BY s.SuppCode
HAVING MIN(s.Price) > (SELECT AVG(s2.Price) FROM Stocks s2);