我想给表TJGL添加一列 total, 同时添加里面的记录,记录是由列times的记录*列money的记录组成,怎么做?
表TJGL 结构
code item times money
1 浇水 3次 15元/亩
我的做法:
用alter table TJGL add total Decimal(10) NULL
可以添加一个列
用select money30times as total from TJGL
可以临时显示列total,可是其他的列看不见
怎么办?
---------------------------------------------------------------
haha...
select code, item, times, money, money30times as total from TJGL
---------------------------------------------------------------
那你可以用
SELECT code, item, times,sum(total) AS A from TJGL group by code, item, times
---------------------------------------------------------------
alert table add total Decimal(10) NULL
select code,money30times as total into #mytemp from TJGL
update TJGL set total=t2.total
from TJGL t1
join #mytemp t2 on t1.code=t2.code
---------------------------------------------------------------
1.alter table TJGL add total decimal(10) null
go
update TJGL set total = money30times
go
select sum(total) from TJGL
2.select sum(money30times ) from TJGL