我有以下兩個表(簡化架構):更新一行加入和最大
score
-----
id
score
score_history
-------------
id
score_id (foreign key with score table)
score
我週期性填充score_history表。我想更新分數表中的每一行,分數列基於score_history中與最大id號關聯的分數。
一個例子可以是:
score entries
+----+-------+
| id | score |
+----+-------+
| 1 | 0 |
| 2 | 0 |
+----+-------+
score_history entries
+----+----------+-------+
| id | score_id | score |
+----+----------+-------+
| 1 | 1 | 15 |
| 2 | 2 | 10 |
| 3 | 1 | 14 |
| 4 | 2 | 11 |
+----+----------+-------+
項3/4 score_history存在之前,我想,在一個請求,以更新從評分表分數是以下幾點:
+----+-------+
| id | score |
+----+-------+
| 1 | 15 |
| 2 | 10 |
+----+-------+
後
+----+-------+
| id | score |
+----+-------+
| 1 | 14 |
| 2 | 11 |
+----+-------+
:將條目score_history 3/4,我再次被有我的成績表像相同的請求喜歡
我嘗試了很多東西(如https://stackoverflow.com/a/9396897/916630),但無法成功。
任何想法?
謝謝,它工作。 – 2015-04-01 12:55:07