SQL:我想使用两个具有相同名称的列来计算新列中的值

时间:2013-06-19 13:05:11

标签: sql

我想做的是:

1月表

Cusip编号:1,2,3

当前因素:.123,.140,.045

二月表

Cusip编号:1,2,3

当前因素:.184,.163,.033

然后在FEB表中找到一个新列,找到每个CUSIP号的2月因子/ jan因子的值:

= 123 / 0.184

=。140 / 0.163

等。

这是我到目前为止从上个月拉出因子并将其显示在2月表之下

SELECT [CURRENT FACTOR]
FROM DBO.mbs012013, DBO.mbs022013
WHERE DBO.mbs012013.[CUSIP NUMBER] = DBO.mbs022013.[CUSIP NUMBER]

2 个答案:

答案 0 :(得分:1)

Update February 
  Set factor= (1.0 * January.factor/February.factor )
  from February 
  Join Janaury on .... whatever links Febuary to January which had better be a 1-1 join

答案 1 :(得分:0)

  SELECT February.CUSIP, February.factor, (1.0 * January.factor/February.factor ) as Ratio
  from February 
  INNER JOIN Janaury on January.CUSIP = February.CUSIP