要实现的功能:将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);
实现之后的效果图:

本文介绍如何使用SQL通过三种方法(多表查询、内连接及直接更新)将两个表中的相关数据进行融合,创建新表或将一列数据更新为另一表中的对应列数据,适用于数据整合场景。
594

被折叠的 条评论
为什么被折叠?



