我有这张叫 shop 表:
+---------+---------+------------+----------+ | shop_id | item_id | item_price | item_qty | +---------+---------+------------+----------+ | 1 | 1 | 0 | 99 | | 2 | 2 | 0 | 99 | | 3 | 3 | 0 | 99 | | 4 | 4 | 0 | 99 | | 5 | 5 | 0 | 99 | | 6 | 6 | 0 | 99 | | 7 | 7 | 0 | 99 | | 8 | 8 | 0 | 99 | +---------+---------+------------+----------+
我也有这张桌子叫做 item :
+---------+-----------------+-----------+----------+----------+----------+---------------------------------+-----------+------------+ | item_id | item_name | item_type | item_atk | item_def | item_atr | item_img | item_desc | item_price | +---------+-----------------+-----------+----------+----------+----------+---------------------------------+-----------+------------+ | 0 | Halberd | 1 | 220 | 20 | 0 | pics/weapons/halberd.png | | 400 | | 1 | Axe | 1 | 220 | 10 | 0 | pics/weapons/axe.png | | 200 | | 2 | Wooden Sword | 1 | 70 | 0 | 0 | pics/weapons/wooden-sword.png | | 225 | | 3 | Dagger | 1 | 60 | 5 | 0 | pics/weapons/dagger.png | | 55 | | 4 | Bow | 1 | 120 | 1 | 0 | pics/weapons/bow.png | | 120 | | 5 | Helmet | 4 | 0 | 50 | 0 | pics/headgears/helmet.png | | 155 | | 6 | Tunic | 2 | 10 | 10 | 0 | pics/armors/tunic.png | | 50 | | 7 | Armour | 2 | 0 | 75 | 0 | pics/armors/armour.png | | 150 | | 8 | Necklace | 3 | 25 | 15 | 0 | pics/accessories/necklace.png | | 199 | | 9 | Studded Leather | 2 | 25 | 60 | 0 | pics/armors/studded-leather.png | | 240 | +---------+-----------------+-----------+----------+----------+----------+---------------------------------+-----------+------------+
我主要想做的是:根据 项目* 表的 item_price 更新 shop 表的* item_price * 。 *
免责声明
询问此查询的目的是从item item_price表中填写我的商店item_price。但是将来的商店item_price的价值将与item_price的价值不同。
例如:
从商店购买的商品将使用商店的item_price。 卖给商店的商品将基于item_price。
您可以简单地通过加入表格来做到这一点。
UPDATE shop a INNER JOIN item b ON b.item_ID = a.item_ID SET a.item_price = b.item_price
UPDATE语句执行后的输出
UPDATE
╔═════════╦═════════╦════════════╦══════════╗ ║ SHOP_ID ║ ITEM_ID ║ ITEM_PRICE ║ ITEM_QTY ║ ╠═════════╬═════════╬════════════╬══════════╣ ║ 1 ║ 1 ║ 200 ║ 99 ║ ║ 2 ║ 2 ║ 225 ║ 99 ║ ║ 3 ║ 3 ║ 55 ║ 99 ║ ║ 4 ║ 4 ║ 120 ║ 99 ║ ║ 5 ║ 5 ║ 155 ║ 99 ║ ║ 6 ║ 6 ║ 50 ║ 99 ║ ║ 7 ║ 7 ║ 150 ║ 99 ║ ║ 8 ║ 8 ║ 199 ║ 99 ║ ╚═════════╩═════════╩════════════╩══════════╝