繁体   English   中英

SQL Server 2005在列中划分两行

[英]SQL Server 2005 Dividing two rows in a column

我有一个这样的表:

        Description                Jan |  Feb  | Mar  | Apr .....   
Volume        

Days in Month

Gal/Day Average

我希望能够将每个月的交易量除以天数(并乘以100)来填写每个月的gal /天平均行。

我最聪明的代码是:

Update Table
set [Jan] = ?
where Description = 'Gal/Day Average'

这不是很好的数据格式,但是您可以执行以下操作:

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';

更好的数据格式将具有以下列:

  • (可能是年份)
  • 体积
  • daysinmonth
  • 平均

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM