我有一张table:
+---------------+------------+-------+-------------+
| name | id_product | price | price_medium|
+---------------+------------+-------+-------------+
| phone | 1 | 300 | 300 |
| mouse | 2 | 50 | 75 |
| phone | 1 | 250 | 300 |
| keyboard | 3 | 100 | 100 |
| mouse | 2 | 100 | 75 |
| phone | 1 | 350 | 300 |
+---------------+------------+------+--------------+
在表b中是一个临时表,每次购买时都会添加产品,然后删除。发送时,我想在表a中更新表b中的“price\u medium”列,该列的产品id是加法。
+---------------+------------+-------+-------------+
| name | id_product | price | price_medium|
+---------------+------------+-------+-------------+
| phone | 1 | 100 | 220 |
| mouse | 2 | 125 | 92 |
| phone | 1 | 100 | 220 |
+---------------+------------+------+--------------+
最终结果见表a
+---------------+------------+-------+-------------+
| name | id_product | price | price_medium|
+---------------+------------+-------+-------------+
| phone | 1 | 300 | 220 |
| mouse | 2 | 50 | 92 |
| phone | 1 | 250 | 220 |
| keyboard | 3 | 100 | 100 |
| mouse | 2 | 100 | 92 |
| phone | 1 | 350 | 220 |
+---------------+------------+------+--------------+
1条答案
按热度按时间nwo49xxi1#
你可以做一个
Inner Join
在两张table之间使用id_product
使用Set
更新price_medium
表A中(等于price_medium
在表b中)尝试: