挿入ステートメントで数値を最大 + 1 の数値に連結しようとしていますが、少し行き詰まっています。私のテーブルは次のようになります。
CREATE TABLE `articles` (
`artcId` INT(10) NOT NULL AUTO_INCREMENT,
`artcUserId` INT(10) NOT NULL DEFAULT '0',
`artcStackId` INT(10) NOT NULL DEFAULT '0',
`artcPublicId` INT(10) ZEROFILL NOT NULL DEFAULT '0',
`artcCountry` VARCHAR(2) NULL DEFAULT NULL,
`artcTitle` VARCHAR(200) NULL DEFAULT NULL,
PRIMARY KEY (`artcUserId`, `artcId`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM;
私の現在のSQLは次のようなものです:
insert into articles (artcUserId, artcStackId, artcCountry, artcTitle)
select 4,IFNULL((MAX(artcStackId)+1) ,0),'US','Hello World'
FROM articles;
私がしようとしているのは、数値を新しい artcStackId に連結し、それをデータベースに保存することです。しかし、私は立ち往生しています。2 番目の画像 artcPublicId を参照してください。
insert into articles (artcUserId, artcStackId, artcCountry, artcTitle)
select 2,IFNULL((MAX(artcStackId)+1) ,0),
case when new.artcCountry = 'US' then conact(91, -- the new artcStackId goes here --)
when new.artcCountry = 'UK' then conact(92, -- the new artcStackId goes here --)
when new.artcCountry = 'CA' then conact(93, -- the new artcStackId goes here --)
end
,'UK','Hello World'
FROM articles;
select * from articles;
これを行う方法はありますか?artcPublicId は、国と新しい artcStackId に応じて 91 または 92 または 93 です。