求救!!
怎样在原有数据库里添加新字段,并且该字段能对原字段数据进行汇总。
例如:
原来数据库 修改后数据库
名称 单价 数量 名称 单价 数量 总金额(添加的新字段)
略 10 10 略 10 10 100
10 20 10 20 200
8 8 8 8 64
修改之后总金额字段的数据能立即显示,望高手给个在SQL 2000 Server具体修改方法,多谢了
怎样在原有数据库里添加新字段,并且该字段能对原字段数据进行汇总。
例如:
原来数据库 修改后数据库
名称 单价 数量 名称 单价 数量 总金额(添加的新字段)
略 10 10 略 10 10 100
10 20 10 20 200
8 8 8 8 64
修改之后总金额字段的数据能立即显示,望高手给个在SQL 2000 Server具体修改方法,多谢了
create table #t(名称 varchar(100), 单价 varchar(100), 数量 int)
go
insert into #t(名称,单价,数量)
select 'name1',10,10 union all
select 'name2',10,20 union all
select 'name2',8,8select * from #talter table #t add 总金额 int
goupdate #t set 总金额=数量*单价select * from #tdrop table #t
c AS a*b
对你原来的数据可以计算,新添加的记录也能计算
go
insert into #t(名称,单价,数量)
select 'name1',10,10 union all
select 'name2',10,20 union all
select 'name2',8,8select * from #talter table #t add 总金额 as 单价*数量select * from #tdrop table #t
go
insert into #t(名称,单价,数量)
select 'name1',10,10 union all
select 'name2',10,20 union all
select 'name2',8,8select * from #talter table #t add 总金额 as 单价*数量select * from #tdrop table #t