Weighted product? I want sum( a*b/sum(b))

  • Having trouble working out the return of an index, where the return is the sum of the contributions (a*b/sum(b)). a is the return. b is the market cap. b/sum(b) is the weight of each stock.

  • Can u post ur SQL?

     

  • What do your tables look like? And it would help to see some sample data and the result(s) you want from that data.

    -SQLBill

  • Easier than I thought;

     

    select sum(A * B)/ SUM(B)

     

    Works a treat.

  • select sum(a*b) / (select sum(b) from...where....) from... where

    I like the complicated version of things....

    Probably you'd want the from...where to be the same in both statements, but it has worked for me this way few times to have my way with things.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply