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

如何按帳戶代碼長度對帳戶求和?

How to sum Accounts by account code length?(如何按帳戶代碼長度對帳戶求和?)
本文介紹了如何按帳戶代碼長度對帳戶求和?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有 2 個表:DimAccounts 和 FactBudget.

I have 2 tables: DimAccounts and FactBudget.

DimAccounts 示例:

DimAccounts example:

AccountKey  AccountCode     AccountName AccountGroup    AccountType
1.6 1         6 1               NN          6               S
1.6 10        6 10              MMM         6               S
1.6 101       6 101             TTT         6               S
1.6 1010      6 1010            IIII        6               B
1.6 1011      6 1011            OOOO        6               B
1.6 1012      6 1012            KKK         6               B

FactBudget 示例:

FactBudget example:

TimeKey    AccountKey   Debit   Credit
20110719    1.6 1010    20.00   5.00
20110719    1.6 1011    15.00   0.00
20110719    1.6 1000    5.00    0.00
20110719    1.6 1012    10.00   5.00
20110719    1.6 1112    10.00   0.00

事實上,Budget 有很多賬戶只有類型 B.我需要獲取賬戶類型 S(總和)的借方和貸方金額.

In FactBudget are many Accounts just with type B. I need to get Debit and Credit Sums for Account type S (Sum).

示例數(shù)據(jù)的解決方案示例:

Solution example for example data:

TimeKey   AccountKey   Debit    Credit
20110719    1.6 1     60.00    10.00
20110719    1.6 10    50.00    10.00
20110719    1.6 101   45.00    10.00

要計算總賬戶 1.6 101(帶空格的 7 個符號)的借方和貸方,我們需要對所有賬戶進行子串,實際預算最多為 7 個符號(1.6 1012 -> 1.6 101, 1.6 1112 -> 1.6 111, 1.6 1011->1.6 101) 那么它們在哪里相等(1.6 101 = 1.6 101) 按時間鍵和借方和貸方總和進行分組.

To calculate debit and credit for sum account 1.6 101 (7 symbols with whitespace) we need to substring all acounts in factbudget up to 7 symbols (1.6 1012 -> 1.6 101, 1.6 1112 -> 1.6 111, 1.6 1011->1.6 101) and then where are they equal (1.6 101 = 1.6 101) to group by timekey and sum debit and credit.

要計算總賬戶 1.6 1(帶空格的 5 個符號)的借方和貸方,我們需要對所有賬戶進行子串,實際預算最多為 5 個符號(1.6 1012 -> 1.6 1, 1.6 1112 -> 1.6 1, 1.6 1011->1.6 1) 那么它們在哪里相等(1.6 1 = 1.6 1) 按時間鍵分組,借記和貸記總和:) 等等.

To calculate debit and credit for sum account 1.6 1 (5 symbols with whitespace) we need to substring all acounts in factbudget up to 5 symbols (1.6 1012 -> 1.6 1, 1.6 1112 -> 1.6 1, 1.6 1011->1.6 1) and then where are they equal (1.6 1 = 1.6 1) to group by timekey and sum debit and credit:) and so on.

那么,如何通過 TimeKey 和 AccountKey 獲取 S Accounts Debit 和 Cred Sum?

So, How to get S Accounts Debit and Cred Sum by TimeKey and AccountKey?

推薦答案

基本上,你可以采用 this answer 并更改其中一個連接條件:

Basically, you could take this answer and just change one of the join conditions:

SELECT
  f.TimeKey,
  s.AccountKey,
  SUM(f.Debit) AS Debit,
  SUM(f.Credit) AS Credit
FROM DimAccounts s
  INNER JOIN DimAccounts b ON b.AccountCode LIKE s.AccountCode + '%'
  /* alternatively: ON s.AccountCode = LEFT(b.AccountCode, LEN(s.AccountCode)) */
  INNER JOIN FactBudget  f ON f.AccountKey = b.AccountKey
WHERE s.AccountType = 'S'
  AND b.AccountType = 'B'
GROUP BY
  f.TimeKey,
  s.AccountKey

這篇關(guān)于如何按帳戶代碼長度對帳戶求和?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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(從逗號或管道運算符字符串中刪除重復項)
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)
主站蜘蛛池模板: 中文字幕一区二区三区四区 | 中文字幕国产 | 亚洲免费视频网站 | 日韩在线不卡 | 久久av一区二区三区 | 国色天香成人网 | 免费看黄色视屏 | 欧美精品二区 | 播放一级黄色片 | 亚洲精品美女在线观看 | 欧美日韩淫片 | www精品 | 天天操夜夜操 | 精品成人69xx.xyz | 久久国产亚洲精品 | 日韩一区二区三区在线观看 | 日韩一区二区免费视频 | 性大毛片视频 | 天天综合久久 | 毛片入口 | 国产精品久久久久久久久 | 欧美伦理一区 | 成人 在线 | 国产精品海角社区在线观看 | 欧美精品欧美精品系列 | 成人免费一区二区三区视频网站 | 狠狠综合久久av一区二区老牛 | 一区二区亚洲 | 亚洲国产成人精品久久久国产成人一区 | 欧美中文字幕在线观看 | 视频一区二区在线观看 | 99精品视频免费观看 | 九九伊人sl水蜜桃色推荐 | 国产精品久久久久久妇女 | 国产三级一区二区 | 亚洲精品久久久9婷婷中文字幕 | www.天堂av.com | 伊人精品在线 | 亚洲成人第一页 | 一区二区在线不卡 | 日本天堂视频在线观看 |