繁体   English   中英

mysql 从其他表插入新列

[英]mysql insert new colum from other table

我有两张桌子,一张是xxx.goods ,一张是xxx.drp.good

xxx.goods表内

cat_id
goods_sn
goods_name
goods_name_style
click_count
brand_id
provider_name
goods_number
goods_weight
market_price
shop_price
promote_price
promote_start_date
promote_end_date
warn_number
keywords
goods_brief
goods_desc
goods_thumb
goods_img
original_img
is_real
extension_code
is_on_sale
is_alone_sale
is_shipping
integral
add_time
sort_order
is_delete
is_best
is_new
is_hot
is_promote
bonus_type_id
last_update
goods_type
seller_note
give_integral
rank_integral
suppliers_id
is_check

在 xxx.drp.goods 表

goods_id
touch_sale
touch_fencheng

如何在xxx.goods表中添加列goods_id touch_sale touch_fencheng

就是这样,这两个数据库都是商品的明细,但是只有xxx.drp.goods记录了商品的配送量。 每当我在系统后端填写分配金额时,它就会添加到xxx.drp.goods中。 如果我不添加它,xxx.drp.goods 就没有该产品的分销记录。 因此,我需要在系统后端手动添加分配金额。 xxx.goods 的数据库包含货物的所有详细信息,但配送金额除外。 有什么办法可以在 xxx.goods 上添加分配金额? 而且我只是在 mysql 上批量修改所有产品分配数量。 而不是在系统后台一一输入产品的配送金额。

我假设您的所有 3 列都有数值。

我将展示如何为 1 列(“goods_id”)执行此操作,您可以复制其他列并以相同的方式进行操作。 所以这里是代码:

ALTER TABLE xxx.goods ADD COLUMN goods_id TINYINT UNSIGNED DEFAULT 0;

然后是第二个查询:

UPDATE xxx.goods t1
INNER JOIN xxx.drp.goods t2 ON t1.id = t2.id 
SET t1.goods_id = t2.goods_id;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM