title: How to combine multiple complex queries?
body: <p>There is a query that displays data by id (R_PERS_ACCOUNT_ID) and date (MAX(RBS.CREATE_DATE))</p>
  <pre><code>Select rpao.r_pers_account_id, max(rbs.create_date)
  from r_base_trans rbs
           join r_pers_acc_operation rpao on rbs.r_base_trans_id = rpao.r_base_trans_id
  where rbs.create_date between to_date('01.12.2017', 'dd.mm.yyyy') and to_date('31.12.2020', 'dd.mm.yyyy')
    and rbs.M_BASE_TRANS_TYPE_ID NOT IN 26
    and ROWNUM &lt; 100
  group by rpao.r_pers_account_id;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Z09td.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>There is one more request in which you need to insert data from the previous select. In the where clause where pa.r_pers_account_id, you need to insert the id from the previous table. And in to_date('31-01-2018', 'dd-mm-yyyy') there is also date data from the previous table. (In my case, I manually inserted only one data)</p>
  <pre><code>select TP.IIN_BIN,
         pa.r_pers_account_id,
         pa.close_date,
         kbk.kbk_code,
         org.code_nk,
         org.CODE_TPK,
         op.m_operation_type_id,
         pa.open_date,
         sum(op.amount)
  from r_pers_account pa
           join r_tax_payer tp on pa.r_tax_payer_id = tp.r_tax_payer_id
           join r_pers_acc_operation op on op.r_pers_account_id = pa.r_pers_account_id
           join m_kbk kbk on kbk.m_kbk_id = pa.m_kbk_id
           join m_tax_org org on org.m_tax_org_id = pa.m_tax_org_id
  where pa.r_pers_account_id in (16616864)
    and is_charge_fine = 0
    and trunc(op.actual_date, 'fmdd') &lt;= to_date('31-01-2018', 'dd-mm-yyyy')
    and op.m_operation_type_id = 1
  group by tp.IIN_BIN, pa.r_pers_account_id, pa.close_date, kbk.kbk_code, op.m_operation_type_id, org.code_nk,
           org.code_tpk, pa.open_date;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/O9N0p.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>In this select, you also need to insert data by id and date.</p>
  <pre><code>select TP.IIN_BIN,
         pa.r_pers_account_id,
         pa.close_date,
         kbk.kbk_code,
         org.code_nk,
         org.CODE_TPK,
         op.m_operation_type_id,
         pa.open_date,
         sum(op.amount)
  from r_pers_account pa
           join r_tax_payer tp on pa.r_tax_payer_id = tp.r_tax_payer_id
           join r_pers_acc_operation op on op.r_pers_account_id = pa.r_pers_account_id
           join m_kbk kbk on kbk.m_kbk_id = pa.m_kbk_id
           join m_tax_org org on org.m_tax_org_id = pa.m_tax_org_id
  where pa.r_pers_account_id in (16616864)
    and is_charge_fine = 0
    and trunc(op.actual_date, 'fmdd') &lt;= to_date('31-01-2018', 'dd-mm-yyyy')
    and op.m_operation_type_id = 2
  group by tp.IIN_BIN, pa.r_pers_account_id, pa.close_date, kbk.kbk_code, op.m_operation_type_id, org.code_nk,
           org.code_tpk, pa.open_date;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Jy0Qv.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p><strong>It is necessary to make so that these 3 requests were one select.</strong></p>
  <p>In addition, after combining these queries, you need to display data by condition if the second select column sum(op.amount) has a negative number, and the third select column sum(op.amount) has 0 or a positive number</p>