我试图将来自4个不同表的4列总和插入到一个单独的表(名为bugs
)触发器中,如下所示:
SELECT
uat_reopened_stats.release_name,
(uat_reopened_stats.rate_bugs + qa_reopened_stats.rate_bugs + closed_reopened_stats.rate_bugs + done_reopened_stats.rate_bugs)
INTO @releasename, @bugstotalreopenrate
FROM qa_reopened_stats
JOIN uat_reopened_stats
ON qa_reopened_stats.release_name = uat_reopened_stats.release_name
JOIN closed_reopened_stats
ON closed_reopened_stats.release_name = uat_reopened_stats.release_name
JOIN done_reopened_stats
ON done_reopened_stats.release_name = uat_reopened_stats.release_name;
INSERT INTO release_stats (release_name, bugs_total_reopen_rate)
VALUES (@releasename, @bugstotalreopenrate)
ON DUPLICATE KEY UPDATE
release_name=@releasename,
bugs_total_reopen_rate=@bugstotalreopenrate;
END
但是,当执行触发器时(事先将release_stats
表清空),最后我得到的行有11(!)行!
MySQL [jira_statistics]> select * from release_stats;
+--------------+------------------------+
| release_name | bugs_total_reopen_rate |
+--------------+------------------------+
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
| 2.3.0 | 9.090909004211426 |
+--------------+------------------------+
为什么会这样?
答案 0 :(得分:0)
由于某种原因,在将release_name
设置为表release_stats
的主键后,问题消失了。