我有一个看起来像这样的表:
+--------------+------------+-------------+
| TaxAuthority | Effective | AuthTaxRate |
+--------------+------------+-------------+
| city1 | 1993-01-01 | 1.0 |
| city1 | 1994-01-01 | 1.5 |
| city2 | 1993-09-01 | 1.5 |
| city2 | 1994-01-01 | 2.0 |
| city2 | 1995-01-01 | 2.5 |
| city3 | 1993-01-01 | 1.9 |
| city3 | 1993-07-01 | 2.3 |
| county1 | 1993-01-01 | 2.3 |
| county1 | 1994-10-01 | 2.5 |
| county1 | 1995-01-01 | 2.7 |
| county2 | 1993-01-01 | 2.4 |
| county2 | 1994-01-01 | 2.7 |
| county2 | 1995-01-01 | 2.8 |
| state1 | 1993-01-01 | 0.5 |
| state1 | 1994-01-01 | 0.8 |
| state1 | 1994-07-01 | 0.9 |
| state1 | 1994-10-01 | 1.1 |
+--------------+------------+-------------+
我正在尝试选择 1994 年 11 月 1 日 city2 的税率。示例:
City2 = 2.0
County1=2.5
State1=1.1
Total=5.6
到目前为止,我已经能够得到加起来为 5.6 的所有金额;但是,我不知道如何将 3 个总和相加。这是我到目前为止的声明:
select AuthTaxRate
from TaxRates
where TaxAuthority = 'City2'
and Effective <= '1994-11-01'
and Effective > '1993-09-01'
union
select AuthTaxRate
from TaxRates
where TaxAuthority = 'County1'
and Effective <= '1994-11-01'
and Effective > '1993-09-01'
union
select AuthTaxRate
from TaxRates
where TaxAuthority = 'State1'
and Effective <= '1994-11-01'
and Effective > '1994-07-01';
我的陈述结果是:
+-------------+
| AuthTaxRate |
+-------------+
| 2.0 |
| 2.5 |
| 1.1 |
+-------------+
有谁知道如何将这些值相加?