久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQL Server 2012:加權(quán)平均計(jì)算

SQL Server 2012: Weighted Average Calculation(SQL Server 2012:加權(quán)平均計(jì)算)
本文介紹了SQL Server 2012:加權(quán)平均計(jì)算的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試計(jì)算表格中某些數(shù)據(jù)的加權(quán)平均成熟度.

I'm trying to calculate the weighted average maturity of some data in my table.

SaleEventID  LID(PK)    CurrentUPB         Interest Rate    RemainingMonths
1            1          $100,000.00         6.100%           11.00
1            2          $67,000.00          6.200%           360.00
1            3          $1,400,000.00       6.300%           240.00
1            4          $500,000.00         7.000%           100.00
2            5          $1,400,000.00       7.100%           240.00
2            6          $500,000.00         7.000%           100.00

所以我想要完成的公式是 (WAM):
1) 乘以 CurrentUPB * RemainingMonths for LID=1
2) 對匹配 WHERE SaleEventID=1
的每一行執(zhí)行此操作3) 對以上計(jì)算求和 = $411,220,000.00 = A
4) SUM 所有 CurrentUPB WHERE SaleEventID=1 等于 $2,067,000.00 =B
5) 然后除以 A/B = $198.95 這是我的 WAM

So the formula i'm trying to accomplish is (WAM):
1) Multiply CurrentUPB * RemainingMonths for LID=1
2) Do that for each row that matches WHERE SaleEventID=1
3) SUM the above calculation = $411,220,000.00 = A
4) SUM all the CurrentUPB WHERE SaleEventID=1 which equals $2,067,000.00 =B
5) Then Divide A/B = $198.95 which is my WAM

我需要考慮的是,在我的表中,我將有許多貸款,并且每個(gè)貸款都不會(huì)被賦予相同的 SaleEventID 值(不是主鍵)

I need to consider that in my table I will have many Loans and that each will not be attributed the same SaleEventID value (Which is not the Primary Key)

到目前為止我的查詢:

SELECT l.*, A / B FROM AS WAM
FROM ( SELECT LSX_DC_Loans l
        (SELECT CurrentUPB * RemainingMonths FROM l WHERE LID = 1
         ) AS A
        (SELECT SUM (CurrentUPB) CurrentUPB FROM LSX_DC_Loans
        WHERE SaleEventID = 1
        ) AS B
FROM l
) l

我無法弄清楚如何執(zhí)行第 2 步和;4. 任何幫助,示例高度贊賞.

I'm having trouble figuring out how to do steps 2 & 4. Any help, examples highly appreciated.

推薦答案

計(jì)算 WAM 和 WAIR 非常簡單.想想 Excel 中的 sumproduct()

To calculate WAM and WAIR is pretty simple. Think sumproduct() in Excel

Declare @YourTable table (SaleEventID  int,LID int,CurrentUPB money,[Interest Rate] money,RemainingMonths money)
Insert Into @YourTable values
(1,1,100000.00,6.100, 11.00),
(1,2,67000.00,6.200, 360.00),
(1,3,1400000.00,6.300, 240.00),
(1,4,500000.00,7.000, 100.00),
(2,5,1400000.00,7.100, 240.00),
(2,6,500000.00,7.000,100.00)


Select SaleEventID
      ,UPB  = sum(CurrentUPB)
      ,WAM  = sum(CurrentUPB*RemainingMonths)/sum(CurrentUPB)
      ,WAIR = sum(CurrentUPB*[Interest Rate] )/sum(CurrentUPB)
 From  @YourTable
 Where SaleEventID = @Event
 Group By SaleEventID

退貨

SaleEventID UPB         WAM         WAIR
1           2067000.00  198.9453    6.4564
2           1900000.00  203.1578    7.0736

這篇關(guān)于SQL Server 2012:加權(quán)平均計(jì)算的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 久久久久免费精品国产小说色大师 | 伊久在线| www.中文字幕 | 尤物在线精品视频 | 欧美二三区 | 成人国产精品久久 | 亚洲精品福利在线 | 色播视频在线观看 | www.99热这里只有精品 | 有码一区 | 久久av一区| 午夜一区二区三区在线观看 | 亚洲福利一区 | 国产中文区二幕区2012 | 久久99精品国产99久久6男男 | 久久成人精品视频 | 日韩在线不卡视频 | 欧美日韩在线视频一区二区 | 日韩综合在线 | 欧美午夜精品久久久久免费视 | 日韩高清电影 | 午夜视频一区 | 青青草亚洲 | 91在线精品视频 | 一区二区不卡 | 国产在线视频在线观看 | av黄色片 | 色99视频 | 国产精品一区二区三区四区五区 | 亚洲字幕在线观看 | 成人av电影免费在线观看 | 一级欧美视频 | 日韩一区在线播放 | 一区日韩 | 国产亚洲高清视频 | xnxx 日本免费 | 国产最好的av国产大片 | 精品一区二区不卡 | 亚洲精品乱码久久久久久蜜桃91 | www国产成人免费观看视频,深夜成人网 | 一级片在线观看视频 |