我一直在尝试找到从 2 个不同表中对 2 行求和的正确方法。
我可以使用这两个查询轻松识别要求和的行:
select *
from vui_trading_review_form_client
where month = '201202' and client_id='TOTALS';
+--------+------------+-----------+-----------------+-----------------+-----------------+----------------+----------+
| month | dt_end | client_id | amt_balance_GBP | amt_balance_EUR | amt_balance_USD | dt_working_day | order_no |
+--------+------------+-----------+-----------------+-----------------+-----------------+----------------+----------+
| 201202 | 2012-02-29 | TOTALS | 2 | 3 | 4 | 2012-02-29 | 2 |
+--------+------------+-----------+-----------------+-----------------+-----------------+----------------+----------+
select *
from vui_trading_review_form_bank
where month = '201202' and provider='TOTALS';
+--------+------------+----------+-----------------+-----------------+-----------------+----------+
| month | dt_end | provider | amt_balance_GBP | amt_balance_EUR | amt_balance_USD | order_no |
+--------+------------+----------+-----------------+-----------------+-----------------+----------+
| 201202 | 2012-02-29 | TOTALS | 1 | 1 | 1 | 3 |
+--------+------------+----------+-----------------+-----------------+-----------------+----------+
我想要实现的是一个如下所示的表格
+-----------------+-----------------+-----------------+
| amt_balance_GBP | amt_balance_EUR | amt_balance_USD |
+-----------------+-----------------+-----------------+
| 1 | 2 | 3 |
+-----------------+-----------------+-----------------+
前三个总数减去后三个总数。
我已经尝试过加入,但我真的很难得到正确的结果。
任何建议将不胜感激。