[英]SQL Server 2005 Dividing two rows in a column
I have a table set up like this: 我有一个这样的表:
Description Jan | Feb | Mar | Apr .....
Volume
Days in Month
Gal/Day Average
I would like to be able to divide the volume for each month by the Days (and multiply by 100) to fill in the gal/day average row for each month. 我希望能够将每个月的交易量除以天数(并乘以100)来填写每个月的gal /天平均行。
The farthest I've gotten code wise is: 我最聪明的代码是:
Update Table
set [Jan] = ?
where Description = 'Gal/Day Average'
Not a very good data format, but you could do: 这不是很好的数据格式,但是您可以执行以下操作:
Update toupdate
set [Jan] = volume.jan / dim.jan
from table toupdate cross join
table volume cross join
table dim
where toupdate.description = 'Gal/Day Average' and
volume.description = 'Volume' and
dim.description = 'Days In Month';
A much better data format would have the columns: 更好的数据格式将具有以下列:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.