如何创建 Microsoft Access 查询,为那些未分类的交易提供默认交易类型?

how to create a Microsoft Access query that provides a default transaction type for those transactions not categorized?

我如何创建一个为那些未分类的交易提供默认交易类型的查询?

所以假设我有:

目标:

但是:

例子

Transactions
1 XXXX   0
2 YYY    0
3 ZZZ    0

Categories
1 aaa  
2 bbb
3 ccc
4 PersonalDefault

Transaction-Categories (i.e. allocation)
transID  catID       %
1           1        100%
2           2        50%


Query Output I'm After
transTitle  catTitle          AllocatedAmount
xxxx         aaaaa            0
yyyyy        bbbbbb           
yyyyy        PersonalDefault  
zzzzz        PersonalDefault  0

此查询将为您提供所需的结果:

select a.transID, t.name as transname, a.catID, c.name as catname, t.amount * a.pc / 100 as amnt
from allocation a inner join transactions t on a.transID = t.id
inner join categories c on a.catID = c.id
union all 
select a.transID, t.name as transname, 4 as catID, 'PersonalDefault' as catname, t.amount * (100 - a.pc) / 100 as amnt
from allocation a inner join transactions t on a.transID = t.id
where a.pc < 100
union all
select t.id as transID, t.name as transname, 4 as catID, 'PersonalDefault' as catname, t.amount as amnt
from transactions t 
where t.id not in (select transID from allocation)

检查这个 SQL Fiddle(它是 SQL 服务器,但也应该在 Access 中工作)