私はこれらのSQL命令を持っています:
CREATE TABLE discipline (
did INT PRIMARY KEY,
code VARCHAR(127) UNIQUE,
university VARCHAR(127),
number_students INT
) ENGINE=INNODB;
CREATE TABLE precedence(
type VARCHAR(127),
basic INT,
advanced INT,
PRIMARY KEY (basic, advanced),
FOREIGN KEY (basic) REFERENCES discipline(did) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (advanced) REFERENCES discipline(did)
)ENGINE=INNODB;
INSERT INTO discipline VALUES (1,'BD','U1',30);
INSERT INTO discipline VALUES (2,'IBD','U2',30);
INSERT INTO discipline VALUES (3,'SIBD','U3',30);
INSERT INTO precedence VALUES ('optional',1,2);
INSERT INTO precedence VALUES ('mandatory',2,3);
UPDATE discipline SET did=did+did WHERE did=2;
SELECT SUM (DISTINCT did)
命令の結果が6で8(1 + 4 + 3)ではない理由がわかりません。2
更新命令の値(did)は4
?これを説明してもらえますか?ありがとう。