Sql练习201908210951

表结构:

create table SalePlan 
(
    PlanId int identity(1,1) primary key,
    GoodsId int,
    PlanPrice decimal(18,2)
);
go

create table Goods 
(
    GoodsId int identity(1,1) primary key,
    Price decimal(18,2)
);
go

原始数据:

insert into Goods(Price)
values(100);
insert into Goods(Price)
values(200);
insert into Goods(Price)
values(300);
insert into Goods(Price)
values(400);
insert into Goods(Price)
values(500);
go

insert into SalePlan
values(1,0);
insert into SalePlan
values(2,0);
insert into SalePlan
values(3,0);
insert into SalePlan
values(4,0);
insert into SalePlan
values(5,0);
go

一条语句将销售计划的销售金额修改为商品表的价格:

update s set s.PlanPrice = g.Price from SalePlan s,Goods g where s.GoodsId = g.GoodsId;
go

最终结果:

完成.

posted @ 2019-08-21 10:04  ラピスラズリ(Dawn)  阅读(127)  评论(0编辑  收藏  举报