我想知道怎么做!!!。
现在:我有卖家按组划分,提供宠物
宠物位于名为PetTable(PETCode 和 PETName)的表中
CREATE TABLE PetTable (
PETCode VARCHAR(16) UNIQUE NOT NULL,
PETName VARCHAR(32) NOT NULL
);
INSERT INTO PetTable (PETCode, PETName) VALUES
('Pet1','Black Cat'),
('Pet2','Big Dog'),
('Pet3','Gold Fish'),
('Pet4','Parlot'),
('Pet5','Bird'),
('Pet6','Small Dog');
卖家存储在SellerTable(CodeSeller 和 NameSeller)中
CREATE TABLE SellerTable (
CodeSeller VARCHAR(16) UNIQUE NOT NULL,
NameSeller VARCHAR(32) NOT NULL
);
INSERT INTO SellerTable (CodeSeller, NameSeller) VALUES
('Seller0','John '),
('Seller1','Paul '),
('Seller2','David '),
('Seller3','James ');
卖家使用具有 3 个字段( PETCode 、CodeSeller、Quantity)的 SalesTable与宠物相关联
CREATE TABLE SalesTable (
PETCode VARCHAR(16) NOT NULL,
CodeSeller VARCHAR(16) NOT NULL,
Quantity INT NOT NULL
);
INSERT INTO SalesTable (PETCode, CodeSeller, Quantity) VALUES
('Pet1', 'Seller0', '9'),
('Pet2', 'Seller0', '81'),
('Pet3', 'Seller0', '7'),
('Pet4', 'Seller1', '63'),
('Pet5', 'Seller1', '4'),
('Pet6', 'Seller1', '50'),
('Pet2', 'Seller2', '61'),
('Pet5', 'Seller2', '72'),
('Pet4', 'Seller3', '83'),
('Pet2', 'Seller3', '94'),
('Pet1', 'Seller3', '8');
我的查询很简单,如何知道每个 PET 的销售额!PET1,PET2,PET3的所有销售额的总和是多少......继续......
感谢您的宝贵帮助...
安