3

同じテーブルを選択して更新しようとすると、mysql でエラーが発生します

error
#1241 - Operand should contain 1 column(s)

トリガーは

DELIMITER $$
CREATE TRIGGER visitor_validation
BEFORE INSERT ON ratingsvisitors
FOR EACH ROW
BEGIN
SET @ifexists = (SELECT * FROM ratingcounttracks WHERE userid=New.vistorid AND likedate=New.likevalidation AND countfor=New.likeordislike);
IF (@ifexists = NULL) THEN
INSERT INTO  ratingcounttracks(userid, likedate, clickcount,countfor) values (New.vistorid, New.likevalidation ,'1',New.likeordislike);
ELSE
UPDATE ratingcounttracks SET clickcount=clickcount+1 WHERE userid=New.vistorid AND likedate=New.likevalidation AND countfor=New.likeordislike;
END IF;
END$$
4

1 に答える 1

1

問題は、複数の列 ( SELECT * FROM ...) を単一の変数 ( ) に選択していることです@ifexists

解決策は、変数を使用しないことです! 通常の SQL を使用するだけIF NOT EXISTS (...)です:

DELIMITER $$
CREATE TRIGGER visitor_validation
BEFORE INSERT ON ratingsvisitors
FOR EACH ROW
BEGIN
IF NOT EXISTS (SELECT * FROM ratingcounttracks WHERE userid=New.vistorid AND likedate=New.likevalidation AND countfor=New.likeordislike) THEN
    INSERT INTO  ratingcounttracks(userid, likedate, clickcount,countfor) values (New.vistorid, New.likevalidation ,'1',New.likeordislike);
ELSE
    UPDATE ratingcounttracks SET clickcount=clickcount+1 WHERE userid=New.vistorid AND likedate=New.likevalidation AND countfor=New.likeordislike;
END IF;
END$$
于 2012-06-03T04:32:59.157 に答える