UPDATE data SET year="2017", mark='0133', Timestamp="2010-01-14 23:30:00.000"
WHERE year="2017" AND mark='0133';
如果年份和标记存在,它会起作用,但如果不存在,我想将此数据作为新行插入。
ON DUPLICATE KEY无效,因为年份和标记已编入索引,但它们不是唯一键或主键。
更新
我不知道我是否可以在PDO中将其作为查询运行:
DECLARE @numrecords INT
SELECT @numrecords = count(*)
FROM `data`
WHERE `year`='2017'
AND `mark` = '0133'
IF @numrecords > 0 THEN
UPDATE `data`
SET `year` = '2017' , `mark` = '0133' ,`Timestamp` = '2010-01-14 23:30:00.000'
WHERE `year`='2017'
AND `mark` = '0133'
ELSE
INSERT INTO `data` (`year`, `mark`, `Timestamp`)
VALUES ('2017', '0133', '2010-01-14 23:30:00.000')
END IF