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

如何總結賬戶

How to sum Accounts(如何總結賬戶)
本文介紹了如何總結賬戶的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有 3 個表:DimAccounts、DimTime 和 FactBudget.

I have 3 tables: DimAccounts, DimTime and FactBudget.

DimAccounts 示例:

DimAccounts example:

AccountKey  Accouncode  AccountType   AccountFrom   AccountTo 
1.10001     10001       S                  11401    27601
1.10002     10002       S                  11401    16501
1.11000     11000       S                  11401    11508
1.110001    110001      B                   NULL    NULL
1.110002    110002      B                   NULL    NULL
1.11400     11400       S                  11401    11408

DimTime 示例:

DimTime example:

   TimeKey      FullDate
    20020102    2002-01-02
    20020103    2002-01-03
    20020104    2002-01-04

FactBudget 示例:

FactBudget example:

TimeKey     AccountKey              Debit    Credit
20080523    1.110002                0.00    884.00
20080523    1.110001                0.00    4251.96
20100523    1.100002                229.40  0.00
20080523    1.100002                711.79  0.00
20090523    1.110002                0.00    711.79
20080523    1.110001                0.00    229.40
20040523    1.100002                0.00    15619.05

事實上,Budget 有很多賬戶只有類型 B.我需要計算賬戶類型為 S(總和)的借方和貸方金額.AccountFrom 和 AccountTo 列顯示 B 類帳戶從哪里開始求和 (AccountFrom) 和哪里結束 (AccountTo).

In FactBudget are many Accounts just with type B. I need to calculate Debit and Credit Sums where Account type is S (Sum). Columns AccountFrom and AccountTo shows B Type Accounts from where to begin summing (AccountFrom ) and where end (AccountTo).

我已經使用 Cursors 制定了解決方案......但是你知道這很糟糕:) 我認為可以以某種方式對 FactBudget 中的數據進行分組(因為在 factbudget 中還有很多列和行 600k)以及在搜索解決方案時(當我只剩下 60k 行):

I have made solution using Cursors.... buth you know this is very bad :) I think there somehow to Group data in FactBudget (because there also many columns in factbudget and rows 600k) and when search for solution (when I group left just 60k rows):

SELECT [TimeKey], 
       [AccountKey], 
       SUM([Debit]), 
       SUM([Credit]) 
FROM   [dbo].[FactBudget] 
GROUP  BY [TimeKey], 
          [AccountKey] 

那么,如何通過TimeKey和AccountKey獲取S賬戶的借記和貸記金額?(AccountKey 數據類型為 nvarchar)

So, How to get S Accounts Debit and Cred Sum by TimeKey and AccountKey? (AccountKey datatype is nvarchar)

解決方案示例:

TimeKey     AccountKey  Debit    Credit
20080523    1.10002     0.00    2500
20080523    1.11000     0.00    8000
20080524    1.10002     900  0.00

實際上預算中沒有類型為 S 的帳戶!!!!我們需要得到它(例如 1.11000 僅適用于日期 20080523):

select 
SUM(Debit), SUM(Credit)
from FactBudget
LEFT JOIN [DimAccounts]
ON [DimAccounts].[AccountKey] = FactBudget.[AccountKey]   
where CAST([DimAccounts].AccountCode AS INT) >=11401    
and CAST([DimAccounts].AccountCode AS INT) <= 11508
and FactBudget.Timekey = 20080523

但我需要按日期顯示每個 S 帳戶的借記和貸記金額.

推薦答案

據我所知,您需要將 DimAccounts 加入到自身中,才能將 B 類帳戶與其對應的 S 類帳戶關聯起來帳戶,然后加入設置為 FactBudget 的那一行以最終獲得數字.像這樣:

As far as I can see, you need to join DimAccounts to itself to associate B-type accounts with their corresponding S-type accounts, then join that row set to FactBudget to finally obtain the figures. Something like this:

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 BETWEEN s.AccountFrom AND s.AccountTo
  INNER JOIN FactBudget  f ON f.AccountKey = b.AccountKey
WHERE s.AccountType = 'S'
  AND b.AccountType = 'B'
GROUP BY
  f.TimeKey,
  s.AccountKey

這篇關于如何總結賬戶的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“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(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 成年免费大片黄在线观看岛国 | 亚洲 欧美 激情 另类 校园 | 成人国产精品久久久 | 看一级毛片 | 波霸ol一区二区 | 色一级 | 成人性视频免费网站 | 无码国模国产在线观看 | 亚欧性视频 | 久久久久久黄 | 久久69精品久久久久久久电影好 | 涩涩导航| 先锋av资源网 | 免费黄色a视频 | 精品福利一区 | 精品乱码一区二区三四区视频 | 紧缚调教一区二区三区视频 | 91九色视频在线 | 亚洲伊人久久综合 | 97久久精品 | 精品一区二区三 | aaaa网站 | 午夜精品一区二区三区在线观看 | 欧美日韩手机在线观看 | 男女国产视频 | 国产 欧美 日韩 一区 | 国产最新视频在线 | 欧美福利视频一区 | 国产色婷婷精品综合在线手机播放 | jizz亚洲人| 久久婷婷国产 | 亚洲精品久久区二区三区蜜桃臀 | av中文字幕在线 | 浴室洗澡偷拍一区二区 | 日韩中文字幕一区 | 久久精品亚洲欧美日韩久久 | 亚洲成人精选 | 天天操夜夜操 | 欧美久久视频 | 亚洲精品1区 | 第一区在线观看免费国语入口 |