MySQL将一个表是一列替代另一个表的一列

要实现的功能:将salary表中的price列替代掉shop表中的pay列?

(把商品的价格与商品列表组成一个新表)

表A:shop:
在这里插入图片描述
表B:salary:
在这里插入图片描述

解决方法:

方法一: 创建一张新表,多表查询

create table Shopping_list(select id,type,product,shoper,orderdate,price from shop,salary where shop.id = salary.id1);

方法二: 创建一张新表,内连接

create table Shopping_list(select id,type,product,price,shoper,orderdate from shop join salary on shop.id = salary.id1);

方法三: 直接在原表更新,让一列完全更新成另一个表中的一列

update shop1 set pay = (select price from salary where salary.id1 = shop1.id);

实现之后的效果图:

在这里插入图片描述

发布了12 篇原创文章 · 获赞 0 · 访问量 341

猜你喜欢

转载自blog.csdn.net/Junetest/article/details/104842202