基本的に、こちらの回答 を取ることができます 結合条件の 1 つを変更するだけです:
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
プレ>