我有一张桌子(name, date, stat1, stat2, stat3),(name, date)就是PK。当我插入行时,将有重复的键,并且我需要总结三个统计信息。我在Java中对PreparedStatement使用以下查询:
(name, date, stat1, stat2, stat3)
(name, date)
INSERT INTO tb (name, date, stat1, stat2, stat3) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE stat1 = stat1 + ?, stat2 = stat2 + ?, stat3 = stat3 + ?
是否有更简洁的查询来实现?因为我简化了查询,所以那里有十多个统计信息。
INSERT INTO tb (name, date, stat1, stat2, stat3) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE stat1 = stat1 + VALUES(stat1), stat2 = stat2 + VALUES(stat2), stat3 = stat3 + VALUES(stat3)