SQL Server2000 相乘

来源:百度知道 编辑:UC知道 时间:2024/05/17 20:51:08
在同个数据库中,有两张表:A、B
A表中有字段:QTY(数字)、UP(百分数)
B表中有字段:AMT

B表中的AMT=QTY*UP
求AMT 这个SQL语句怎么写?
求救!
UP是百分数,还要除100。

表tba
id amt
1 10
2 40
3 108
4 200
表tbb
id qty up
1 100 0.10
2 200 0.20
3 300 0.36
4 400 0.50

update a set
a.amt=b.qty*b.up
from tba as a
inner join tbb as b
on a.id=b.id

update b set amt=(select qty*up/100 from a where a.b_id = b.id)
b_id 是a表中存储的b表id(也可以改成其他唯一标识)

insert into B(ATM) select QTY*UP from A;--先将数据导入
select AMT from b;--再查询

为什么要这么建呢,这么设计不会造成数据冗余嘛