Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql select sum 2 rows from different tables
    primarykey
    data
    text
    <p>I have been trying to find the correct way to sum 2 rows from 2 different tables.</p> <p>I can easily identify the rows I want to sum using these two queries:</p> <pre><code>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 | +--------+------------+----------+-----------------+-----------------+-----------------+----------+ </code></pre> <p>What I would like to achieve is a table which looks as follows</p> <pre><code>+-----------------+-----------------+-----------------+ | amt_balance_GBP | amt_balance_EUR | amt_balance_USD | +-----------------+-----------------+-----------------+ | 1 | 2 | 3 | +-----------------+-----------------+-----------------+ </code></pre> <p>the first 3 totals minus the second three totals.</p> <p>I have tried a join but i'm really struggling to get the right result.</p> <p>Any suggestions would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload