에 의해 그룹을 사용하여 I가 다음과 같은 테이블 작성 스크립트 : 관계없이/총 금액의 최소 지불 한 고객들의 custid 및 CUSTNAME를 표시하는 쿼리를 작성할 때 나는 오류를 얻고있다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)
);
, 반환 된 항목의
내 쿼리는 다음과 같습니다
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