我有这个扳机
DELIMITER $$
CREATE TRIGGER before_bid_insert
BEFORE INSERT ON Bids
FOR EACH ROW
BEGIN
IF NEW.amount > (SELECT B.amount, B.vin FROM Bids B WHERE B.vin = NEW.vin AND B.amount = (SELECT MAX(amount) from Bids)) THEN
INSERT INTO Notifications (buyer, outbidded, vin, amount) values (NEW.buyer, B.buyer, NEW.vin, NEW.amount);
END IF ;
END$$
DELIMITER ;
有table的
CREATE TABLE Auctions
(seller VARCHAR(100),
vin VARCHAR(20),
brand VARCHAR(20),
cartype VARCHAR(20),
model VARCHAR(20),
color VARCHAR(20),
minprice int,
dt DATETIME,
PRIMARY KEY (vin, seller)
);
CREATE TABLE Bids
(buyer VARCHAR(20),
vin VARCHAR(20),
amount int,
autobid int,
upperlimit int,
PRIMARY KEY(buyer, vin, amount),
FOREIGN KEY (vin) REFERENCES Auctions(vin)
);
CREATE TABLE Notifications
(buyer VARCHAR(20),
outbidded VARCHAR(20),
vin VARCHAR(20),
amount int,
PRIMARY KEY(vin, buyer),
FOREIGN KEY (vin) REFERENCES Bids(vin),
FOREIGN KEY (buyer) REFERENCES Bids(buyer)
);
不过,每当我运行它时,它都会说操作数应该包含1列。
我要做的是,如果要插入的行的amount值比bids表中与新行具有相同vin的任何行的amount值都高,那么将这些值插入到通知中。
1条答案
按热度按时间uqxowvwt1#
您可以这样做来帮助解决这两个问题:
另外,不确定,但我觉得你应该再办理一次入住手续
SELECT MAX(amount) from Bids
查询以包含WHERE
要检查的子句vin
.