表1
单号 日期
001 2010-01-01
002 2020-01-02
表2
单号 货物 单价
001 书本 10
002 椅子 80
问:
如何用sql 语句更新日期为2010-01-01的书本的单价为原单价*2?
单号 日期
001 2010-01-01
002 2020-01-02
表2
单号 货物 单价
001 书本 10
002 椅子 80
问:
如何用sql 语句更新日期为2010-01-01的书本的单价为原单价*2?
表2
set
单价=单价*2
from
表1 a join 表2 b
on
a.单号=b.单号
and
a.日期='2010-01-01'
create table t2(num varchar(5),product varchar(100),price int)insert into t1
select '001','2010-01-01'
union select '002','2020-01-02'insert into t2
select '001','书本',10
union select '002','椅子',80select * from t2
update t2 set price=price*2 where num=(select num from t1 where ddate='2010-01-01')
select * from t2
drop table t1
drop table t2
create table t1(单号 varchar(5),日期 datetime)
create table t2(单号 varchar(5),货物 varchar(100),单价 int)insert into t1
select '001','2010-01-01' union all
select '002','2020-01-02'insert into t2
select '001','书本',10 union all
select '002','椅子',80update t2
set 单价=单价*2
from t1,t2
where t1.单号=t2.单号 and 日期='2010-01-01'
create table tb2(单号 varchar(5),货物 varchar(10),单价 int)insert into tb1
select '001','2010-01-01'
union select '002','2020-01-02'insert into tb2
select '001','书本',10
union select '002','椅子',80update tb2 set 单价 = 单价 * 2 from tb2 , tb1 where tb2.单号 = tb1.单号 and tb1.日期 = '2010-01-01'select * from tb2
/*
单号 货物 单价
----- ---------- -----------
001 书本 20
002 椅子 80(所影响的行数为 2 行)
*/drop table tb1 , tb2