使用組,我有以下表創建腳本:通過在MySQL
CREATE TABLE assetcost(
assettype VARCHAR(20) PRIMARY KEY,
rentamt INT
);
CREATE TABLE furnishitem(
itemid VARCHAR(4) PRIMARY KEY CHECK(itemid LIKE 'I%'),
description VARCHAR(30),
availablesets INT,
assettype VARCHAR(25),
specialCharge CHAR(1) CHECK(specialcharge IN ('Y','N')),
FOREIGN KEY(assettype) REFERENCES assetcost(assettype)
);
CREATE TABLE custdetail(
custid VARCHAR(5) PRIMARY KEY CHECK(custid LIKE 'C%'),
custname VARCHAR(30)
);
CREATE TABLE transaction(
transid INT UNIQUE,
custid VARCHAR(5) ,
itemid VARCHAR(4),
sets INT,
days INT,
amount INT,
returned char(1) Check (returned in('Y','N')),
FOREIGN KEY(custid)REFERENCES custdetail(custid),
FOREIGN KEY(itemid)REFERENCES furnishitem(itemid)
);
編寫查詢時顯示的那些誰也/支付總金額的最低客戶的客戶ID和CUSTNAME我得到的錯誤,不管返回的項目。
我的查詢是:
select t.custid,c.custname
-> from transaction t inner join custdetail c
-> on t.custid=c.custid
-> group by t.custid
-> having sum(amount)=(select min(sum(amount) from transaction group by custid);
什麼是錯誤? – Taryn
在RDBM中,*每個*表原則上都應該有一個PRIMARY KEY。 – Strawberry